intmain(){ scanf("%d", &n); int mx = 0; for (int i = 1; i <= n; i++) scanf("%d", a + i), mx = max(mx, a[i]); int ans = 1, i = 1; while (i <= n) { if (a[i] != mx) i++; else { int j = i; while (j <= n && a[j] == mx) j++; ans = max(ans, j - i); i = j; } } cout << ans << endl; return0; }
intcheck(ll x){ ll k = x / n, r = x % n; ll dx = k * pre[n].first + pre[r].first; ll dy = k * pre[n].second + pre[r].second; ll totx = st.first + dx, toty = st.second + dy; if (abs(totx - ed.first) + abs(toty - ed.second) <= x) return1; elsereturn0; }
intmain(){ scanf("%d%d%d%d%d%s", &st.first, &st.second, &ed.first, &ed.second, &n, s); int dx = 0, dy = 0; for (int i = 0; i < n; i++) { if (s[i] == 'U') dy++; if (s[i] == 'D') dy--; if (s[i] == 'L') dx--; if (s[i] == 'R') dx++; pre[i + 1] = {dx, dy}; } // ll ans = -1; // for (int i = 0; i < n; i++) { // totx = st.first + pre[i].first; // toty = st.second + pre[i].second; // ll l = 1, r = 1e9
// } ll l = 1, r = 1e16, ans = -1; while (l <= r) { ll m = (l + r) / 2; if (check(m)) ans = m, r = m - 1; else l = m + 1; } cout << ans << endl; return0; }
structMat { staticconstint M = 100; ll a[M][M]; Mat() { ms(a, 0); } voidclear(){ ms(a, 0); } voideye(){ for (int i = 0; i < M; i++) a[i][i] = 1; } ll* operator [] (ll x) { return a[x]; } const ll* operator [] (ll x) const { return a[x]; } Mat operator * (const Mat& b) { const Mat& a = *this; Mat r; for (int i = 0; i < M; i++) for (int j = 0; j < M; j++) for (int k = 0; k < M; k++) r[i][j] = (r[i][j] + a[i][k] * b[k][j]) % mod; return r; } Mat pow(ll n)const{ Mat a = *this, r; r.eye(); while (n > 0) { if (n & 1) r = r * a; n >>= 1; a = a * a; } return r; } Mat operator + (const Mat& b) { const Mat& a = *this; Mat r; for (int i = 0; i < M; i++) for (int j = 0; j < M; j++) r[i][j] = (a[i][j] + b[i][j]) % mod; return r; } voidprint()const{ for (int i = 0; i < M; i++) for (int j = 0; j < M; j++) printf("%lld%c", (*this)[i][j], j == M - 1 ? '\n' : ' '); } } A, X, R;
ll n; int m;
intmain(){ cin >> n >> m; if (m > n) returnputs("1"), 0; A[0][0] = A[0][m - 1] = 1; for (int i = 1; i < m; i++) A[i][i - 1] = 1; for (int i = 0; i < m; i++) X[i][0] = 1; cout << (A.pow(n - m + 1) * X)[0][0] << endl; return0; }