QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#359618 | #5173. 染色 | zyc070419 | 0 | 330ms | 14072kb | C++14 | 1.9kb | 2024-03-20 19:30:01 | 2024-03-20 19:30:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 3;
const int B = 15;
inline int read() {
char ch = getchar(); int x = 0;
while (!isdigit(ch)) {ch = getchar();}
while (isdigit(ch)) {x = x * 10 + ch - 48; ch = getchar();}
return x;
}
int n, T, a[N], dp[N][(B << 1) + 2], pre[N][(B << 1) + 2], lst[N], cnt[N];
set<int> S;
int main() {
n = read(); T = read();
for (int i = 1; i <= n; ++i) a[i] = read();
for (int i = 1; i <= n; ++i) {
if (S.find(lst[a[i]]) != S.end()) S.erase(lst[a[i]]);
S.insert(i);
lst[a[i]] = i;
if (S.size() > B) S.erase(S.begin());
auto it = S.begin();
while (it != S.end()) pre[i][cnt[i]++] = a[*it], it++;
}
S.clear();
for (int i = n; i >= 1; --i) {
if (S.find(lst[a[i]]) != S.end()) S.erase(lst[a[i]]);
S.insert(i);
lst[a[i]] = i;
if (S.size() > B) {
auto it = S.end(); it--;
S.erase(it);
}
auto it = S.begin();
while (it != S.end()) pre[i][cnt[i]++] = a[*it], it++;
}
// for (int i = 1; i <= n; ++i) {
// for (int j = 0; j < B; ++j)
// printf("%d ", pre[i][j]);
// puts("");
// }
int l, r;
while (T--) {
l = read(); r = read();
if (l > r) swap(l, r);
for (int i = 0; i < cnt[l]; ++i) dp[l][i] = 1e9;
dp[l][0] = 0;
for (int i = l; i < r; ++i) {
for (int j = 0; j < cnt[i]; ++j) dp[i + 1][j] = 1e9;
for (int p = 0; p < cnt[i]; ++p) {
if (!pre[i][p]) continue;
for (int q = 0; q < cnt[i + 1]; ++q) {
if (!pre[i + 1][q]) continue;
// printf("{%d} %d\n", i + 1, q);
dp[i + 1][q] = min(dp[i + 1][q], dp[i][p] + (pre[i][p] != pre[i + 1][q]) + (pre[i + 1][q] != a[i + 1]));
}
}
for (int j = 0; j < cnt[i + 1]; ++j) dp[i + 1][j]++;
// for (int j = 0; j < B; ++j) printf("dp[%d][%d] = %d\n", i + 1, j, dp[i + 1][j]);
}
int ans = 1e9;
for (int j = 0; j < cnt[r]; ++j) ans = min(ans, dp[r][j]);
printf("%d\n", ans);
}
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 330ms
memory: 14072kb
input:
10000 100 84 85 52 2 78 53 20 21 23 76 37 44 18 5 37 8 81 65 46 58 69 1 69 37 53 46 37 35 35 89 1 77 35 6 46 59 89 46 25 55 50 38 61 67 44 23 29 24 46 4 42 15 34 77 20 34 83 79 12 50 69 26 38 14 9 66 80 72 22 26 9 68 35 38 19 84 92 30 83 62 100 71 81 60 7 37 64 50 33 60 86 75 45 78 32 53 3 48 87 60 ...
output:
3668 4575 5976 8382 729 7013 183 7320 492 1140 254 2249 13226 6254 456 7507 2162 10482 1791 2674 4801 294 5997 627 6654 6179 11414 2712 3157 7836 17783 511 5486 17835 9564 6147 4996 14578 670 463 15613 12655 8873 7834 10987 6602 6399 5023 9102 8528 2173 10299 2694 12537 4958 2143 8809 1907 6476 2828...
result:
wrong answer 11th words differ - expected: '253', found: '254'
Subtask #2:
score: 0
Time Limit Exceeded
Test #7:
score: 0
Time Limit Exceeded
input:
100000 100000 3 2 3 3 3 3 2 3 2 1 3 1 1 1 3 2 1 3 1 2 2 1 3 1 2 2 1 1 1 3 2 1 3 3 3 3 1 1 1 2 3 3 2 1 1 1 3 1 3 1 3 2 1 3 2 3 3 2 3 3 2 3 3 3 3 3 2 3 2 3 1 3 3 3 3 3 3 3 1 2 3 3 1 3 1 1 2 2 3 1 1 2 3 2 3 1 3 2 1 3 2 3 2 1 1 3 3 1 3 1 2 2 2 3 2 3 2 3 2 1 1 3 1 3 2 2 3 3 3 1 2 2 3 3 2 1 3 1 2 2 2 3 2 ...
output:
result:
Subtask #3:
score: 0
Time Limit Exceeded
Test #15:
score: 0
Time Limit Exceeded
input:
5000 5000 256 63 197 36 75 66 33 72 27 75 66 248 29 166 209 252 141 95 84 226 147 249 116 94 192 256 199 273 182 166 116 274 27 211 154 144 283 23 53 110 215 11 164 284 161 221 251 96 43 47 18 115 12 51 156 61 116 209 93 98 47 165 174 106 83 67 184 75 12 290 183 197 112 240 67 56 215 148 104 5 141 2...
output:
result:
Subtask #4:
score: 0
Time Limit Exceeded
Test #23:
score: 0
Time Limit Exceeded
input:
1000000 1000000 1105 3246 1880 3554 818 2331 2576 4140 149 4562 3498 3536 3400 4788 4363 4742 1216 4218 4032 1701 1489 4889 1761 3022 3145 4945 3067 4304 5016 4624 1612 13 1335 3613 1086 2210 386 3464 1156 3352 4341 5006 3465 3900 622 654 1826 2983 1250 4164 3335 4308 2995 1982 1347 4335 2535 5054 4...