QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#94718 | #3236. Hills And Valleys | whatever# | 100 ✓ | 239ms | 11256kb | C++17 | 1.7kb | 2023-04-07 16:24:19 | 2023-04-07 16:24:21 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a, I = b; i <= I; ++i)
#define per(i, a, b) for (int i = a, I = b; i >= I; --i)
using namespace std;
using i64 = long long;
using i128 = __int128_t;
using pii = pair<int, int>;
template<typename T> void up(T &x, T y) { if (x < y) x = y; }
template<typename T> void down(T &x, T y) { if (x > y) x = y; }
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int rng(int l, int r) { return l + rnd() % (r - l + 1); }
const int N = 100005;
char s[N];
int n, f[N][10], g[N][10], l, r, ans;
pii dp[10];
void up(int L, int R, int ANS) {
if (ANS > ans) {
ans = ANS;
l = L, r = R;
}
}
void solve() {
cin >> n >> (s + 1);
rep(i, 1, n) s[i] -= '0';
rep(i, 1, n) {
memcpy(f[i], f[i - 1], sizeof f[i]);
++f[i][s[i]];
rep(j, 1, 9) up(f[i][j], f[i][j - 1]);
}
memset(g[n + 1], 0, sizeof g[n + 1]);
per(i, n, 1) {
memcpy(g[i], g[i + 1], sizeof g[i]);
++g[i][s[i]];
per(j, 8, 0) up(g[i][j], g[i][j + 1]);
}
l = r = 1, ans = f[n][9];
rep(a, 0, 9) rep(b, a + 1, 9) {
rep(j, a, b) dp[j] = {-1e9, 0};
rep(i, 1, n) {
up(dp[b], pii(f[i - 1][a], i));
per(i, b - 1, a) up(dp[i], dp[i + 1]);
if (s[i] >= a && s[i] <= b) ++dp[s[i]].first;
per(i, b - 1, a) up(dp[i], dp[i + 1]);
up(dp[a].second, i, dp[a].first + g[i + 1][b]);
}
}
cout << ans << " " << l << " " << r << "\n";
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int T; cin >> T;
while (T--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 239ms
memory: 11256kb
input:
100 564 3348010339062339968164170543732424036101480063385567796871300633327190066610177797479597931706239956680908434521050648311220502482402268964497684451036156162125014743550622955579737715237323508714467463047351532756224409691528642332476831673220319724437158730801472447651264708417183934709815...
output:
108 78 492 296 760 1295 1419 1 1585 92 46 399 888 745 1073 262 626 1212 338 190 971 258 950 1736 848 2 382 1804 43 1416 102 2 504 103 11 420 99 16 497 263 375 1113 1306 441 488 301 113 851 100 4 199 107 177 471 362 28 281 1108 1 1778 96 293 476 1094 538 1098 1039 63 69 706 533 1340 573 186 1381 91 9...
result:
ok correct answer! (100 test cases)