å ¨æ¢ç´¢æèã«æ £ãã¦ããããã°ã ã®è§£æ³ãªãããã«æãã¤ããå°ã工夫ãã¦ã ã®è§£æ³ã«ãªãï¼
åé¡æ¦è¦
é·ã ã®æ°å ãä¸ãããããæ°å ã®é¨åæ°å ã§ãã£ã¦
- ãçå·®æ°åã§ãã
- ã§ãã
ã¨ããæ¡ä»¶ãæºãããã®ãèããããããã®æ°åã®æ大é·ãæ±ããã
å¶ç´
èãããã¨
ããã¨æãã¤ãã®ã¯ã次ã®è§£æ³ã ã¨æãã
- ãå ¨æ¢ç´¢ãã
- ãã®ããããã«ã¤ãã¦ãçããå¤ãã©ãã¾ã§ç¶ãããæ±ãã
調ã¹ãã¹ããã®ã¯ éããããããããã®å ´åã«å¯¾ãã¦ãçããå¤ãã©ãã¾ã§ç¶ãããæ±ããã®ã«ã¯ ã®è¨ç®éãè¦ããã®ã§ãå ¨ä½ã¨ã㦠ã®è¨ç®éã¨ãªãã
å®ã¯ã¡ããã¨è¨ç®é解æããã¨ãä¸è¨ã®å ¨æ¢ç´¢è§£æ³ã®è¨ç®é㯠ã§ããããã¨ãè¨ãã¦ãããã§ãéãã®ã ãã©ãããã§ã¯ãããåããããã ã®è§£æ³ãèããã
ã
é¨åæ°åã®ééãã¨ã«èãã¦ã¿ã
ããã§ãé¨åæ°åã®éé ã®ã¿ãåºå®ãã¦èãããã¨ã«ããã
ã¾ããæ°å ã¯ãæ·»åã ã§å²ã£ãä½ãã§åé¡ãããã¨ã§ã åã®æ°åã«åãã¦èãããã¨ãã§ããã«æ³¨æãããä¸å³ã¯ , ã®å ´åã 0-indexed ã§ç¤ºãããã®ã§ããããã®ä¾ã§ã¯ãæ·»å 4, 7, 10 ããã¹ã¦å¤ã2ãã§ã3 ãæ大é·ã¨ãªãã
ãã®ããã«æ°åãåããã¨ãåæ°åã«å¯¾ãã¦æ¬¡ã®åé¡ãèããã°ãããã¨ã«ãªãã
ä¸ããããæ°åã«ããã¦ãåãå¤ãæ大ã§ä½åé£ç¶ãã¦ããããæ±ããã
ãã®åé¡ã¯ãæ°åã®é·ãã ã¨ãã¦ã ã®è¨ç®éã§è§£ããã
åã®æ°åã®é·ãã®ç·å㯠ã§ãããããçµå±ã åã®æ°åã«ã¤ãã¦ä¸è¨ã®åé¡ã解ãã®ã«è¦ããè¨ç®é㯠ã¨è©ä¾¡ã§ããã ã éããããããå ¨ä½ã®è¨ç®é㯠ã¨è©ä¾¡ã§ããã
ã³ã¼ã
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> H(N); for (int i = 0; i < N; i++) cin >> H[i]; int res = 1; // æ°åã®éé d ãå ¨æ¢ç´¢ãã for (int d = 1; d < N; d++) { // æ°åå ¨ä½ã d åã«åå²ãã¦è§£ã for (int r = 0; r < d; r++) { // åå²ãã¦å¾ãããæ°åã«å¯¾ãã¦ãåãå¤ãæ大ä½åé£ç¶ãã¦ããããæ±ãã int num = 1, prev = -1; for (int i = r; i < N; i += d) { if (H[i] == prev) { num++; res = max(res, num); } else { num = 1; prev = H[i]; } } } } cout << res << endl; }