QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#546778 | #1955. Double Rainbow | ucup-team052# | WA | 0ms | 3896kb | C++23 | 876b | 2024-09-04 13:32:50 | 2024-09-04 13:32:51 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 10005;
int a[N], cnt[N], cnt2[N], r[N];
int n, k, all, all2;
void add(int x) {
all += (cnt[x] == 0);
++cnt[x];
--cnt2[x];
all2 -= (cnt2[x] == 0);
}
void del(int x) {
--cnt[x];
all -= (cnt[x] == 0);
all2 += (cnt2[x] == 0);
++cnt2[x];
}
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
++cnt2[a[i]];
}
for (int i = 1; i <= k; i++) all2 += (cnt2[i] > 0);
int ans = n + 1;
for (int i = 1; i <= n; i++) {
r[i] = r[i - 1];
while (r[i] < i) {
++r[i];
add(a[r[i]]);
}
while (r[i] < n && all < k) {
++r[i];
add(a[r[i]]);
}
if (all < k) r[i] = n + 1;
if (r[i] != n + 1 && all2 == k) ans = min(ans, r[i] - i + 1);
del(a[i]);
}
if (ans == n + 1) ans = -1;
printf("%d\n", ans);
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3896kb
input:
1 1 1
output:
-1
result:
wrong answer 1st lines differ - expected: '0', found: '-1'