답안 #631584

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
631584 2022-08-18T09:23:55 Z bachhoangxuan Martian DNA (BOI18_dna) C++17
100 / 100
61 ms 4564 KB
#include<bits/stdc++.h>
using namespace std;
#define maxn 200005
int num[maxn],n,k,q,cnt[maxn],a[maxn];
bool check(int mid){
    int x=0;
    for(int i=0;i<k;i++) cnt[i]=0;
    for(int i=1;i<=mid;i++){
        cnt[a[i]]++;
        if(cnt[a[i]]==num[a[i]]) x++;
    }
    if(x==q) return true;
    for(int i=mid+1;i<=n;i++){
        cnt[a[i]]++;
        if(cnt[a[i]]==num[a[i]]) x++;
        if(cnt[a[i-mid]]==num[a[i-mid]]) x--;
        cnt[a[i-mid]]--;
        if(x==q) return true;
    }
    return false;
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cin >> n >> k >> q;
    for(int i=1;i<=n;i++) cin >> a[i];
    for(int i=1;i<=q;i++){
        int x,c;cin >> x >> c;
        num[x]=c;
    }
    int l=1,r=n,ans=-1;
    while(r>=l){
        int mid=(r+l)>>1;
        if(check(mid)){ans=mid;r=mid-1;}
        else l=mid+1;
    }
    if(ans==-1) cout << "impossible\n";
    else cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 324 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 356 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 324 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 1492 KB Output is correct
2 Correct 26 ms 1516 KB Output is correct
3 Correct 18 ms 1492 KB Output is correct
4 Correct 22 ms 1516 KB Output is correct
5 Correct 31 ms 2508 KB Output is correct
6 Correct 22 ms 1496 KB Output is correct
7 Correct 25 ms 1868 KB Output is correct
8 Correct 37 ms 3140 KB Output is correct
9 Correct 27 ms 2004 KB Output is correct
10 Correct 25 ms 1492 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 544 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 3444 KB Output is correct
2 Correct 45 ms 3172 KB Output is correct
3 Correct 43 ms 2824 KB Output is correct
4 Correct 12 ms 1420 KB Output is correct
5 Correct 42 ms 4044 KB Output is correct
6 Correct 61 ms 4564 KB Output is correct
7 Correct 30 ms 2132 KB Output is correct
8 Correct 40 ms 2452 KB Output is correct
9 Correct 26 ms 1492 KB Output is correct
10 Correct 26 ms 1508 KB Output is correct
11 Correct 16 ms 1440 KB Output is correct
12 Correct 23 ms 1516 KB Output is correct
13 Correct 30 ms 2524 KB Output is correct
14 Correct 22 ms 1492 KB Output is correct
15 Correct 23 ms 1588 KB Output is correct
16 Correct 36 ms 3172 KB Output is correct
17 Correct 27 ms 1996 KB Output is correct
18 Correct 27 ms 1496 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct