QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#616965#1955. Double RainbowLavender_Field#Compile Error//C++201.2kb2024-10-06 13:16:242024-10-06 13:16:24

Judging History

你现在查看的是最新测评结果

  • [2024-10-06 13:16:24]
  • 评测
  • [2024-10-06 13:16:24]
  • 提交

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

Details

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);
      |         ~~~~~^~~~~~~~~~~