QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#616965 | #1955. Double Rainbow | Lavender_Field# | Compile Error | / | / | C++20 | 1.2kb | 2024-10-06 13:16:24 | 2024-10-06 13:16:24 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define MAXN 10000
#define MAXK 10000
int n, k;
int a[MAXN+5];
int cnt1[MAXK+5], cnt2[MAXK+5];
int tot1, tot2, ans;
int main() {
scanf("%d %d", &n, &k);
for(int i = 1; i <= n; ++i) {
scanf("%d", a+i);
cnt1[a[i]]++;
if( cnt1[a[i]] == 1 ) ++tot1;
}
int p = n;
while( true ) {
if( cnt1[a[p]] == 1 ) break;
--cnt1[a[p]];
++cnt2[a[p]];
if( cnt2[a[p]] == 1 ) ++tot2;
--p;
}
if( tot2 != k ) {
puts("0");
return 0;
}
ans = p;
for(int i = 2; i <= n; ++i) {
cnt2[a[i-1]]++;
if( cnt2[a[i-1]] == 1 ) ++tot2;
cnt1[a[i-1]]--;
if( cnt1[a[i-1]] == 0 ) --tot1;
while( tot1 < k ) {
++p;
if( p == n+1 ) {
printf("%d", ans);
return 0;
}
++cnt1[a[p]];
if( cnt1[a[p]] == 1 ) ++tot1;
--cnt2[a[p]];
if( cnt2[a[p]] == 0 ) --tot2;
}
if( tot2 == k ) {
ans = min(ans, p - i + 1);
}
}
printf("%d", ans);
return 0;
}123
詳細信息
answer.code:52:2: error: expected unqualified-id before numeric constant 52 | }123 | ^~~ answer.code: In function ‘int main()’: answer.code:11:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 11 | scanf("%d %d", &n, &k); | ~~~~~^~~~~~~~~~~~~~~~~ answer.code:13:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 13 | scanf("%d", a+i); | ~~~~~^~~~~~~~~~~