Submission #330266

# Submission time Handle Problem Language Result Execution time Memory
330266 2020-11-24T10:33:50 Z nandonathaniel Martian DNA (BOI18_dna) C++14
100 / 100
134 ms 12672 KB
#include<bits/stdc++.h>
using namespace std;
 
int mini[200005],byk[200005];
int s[200005];

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int n,k,r,x,y;
    cin >> n >> k >> r;
    for(int i=0;i<n;i++)cin >> s[i];
    for(int i=1;i<=r;i++){
    	cin >> x >> y;
    	mini[x]=y;
	}
	set<int> valid;
	for(int i=0;i<k;i++){
		if(mini[i]==0)valid.insert(i);
	}
	int ans=n+1,awal=0,akhir=0;
    byk[s[0]]++;
    if(byk[s[0]]==mini[s[0]])valid.insert(s[0]);
    while(awal<=akhir && akhir<n){
    	bool stat=(valid.size()==k);
    	if(!stat){
    		if(akhir<n-1){
    			akhir++;
    			byk[s[akhir]]++;
    			if(byk[s[akhir]]==mini[s[akhir]])valid.insert(s[akhir]);
			}
			else break;
		}
		else{
			ans=min(ans,akhir-awal+1);
			byk[s[awal]]--;
			if(byk[s[awal]]==mini[s[awal]]-1)valid.erase(s[awal]);
			awal++;
		}
	}
	if(ans==n+1)cout << "impossible\n";
	else cout << ans << '\n';
	return 0;
}

Compilation message

dna.cpp: In function 'int main()':
dna.cpp:24:29: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   24 |      bool stat=(valid.size()==k);
      |                 ~~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 1516 KB Output is correct
2 Correct 22 ms 1516 KB Output is correct
3 Correct 27 ms 1132 KB Output is correct
4 Correct 23 ms 1132 KB Output is correct
5 Correct 38 ms 5228 KB Output is correct
6 Correct 14 ms 1152 KB Output is correct
7 Correct 15 ms 1132 KB Output is correct
8 Correct 65 ms 11372 KB Output is correct
9 Correct 19 ms 1516 KB Output is correct
10 Correct 15 ms 1132 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 0 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 125 ms 5612 KB Output is correct
2 Correct 110 ms 4460 KB Output is correct
3 Correct 62 ms 4460 KB Output is correct
4 Correct 14 ms 1132 KB Output is correct
5 Correct 38 ms 2796 KB Output is correct
6 Correct 134 ms 10988 KB Output is correct
7 Correct 22 ms 2540 KB Output is correct
8 Correct 29 ms 3436 KB Output is correct
9 Correct 20 ms 1516 KB Output is correct
10 Correct 22 ms 1516 KB Output is correct
11 Correct 26 ms 1516 KB Output is correct
12 Correct 23 ms 1644 KB Output is correct
13 Correct 36 ms 6380 KB Output is correct
14 Correct 14 ms 1516 KB Output is correct
15 Correct 16 ms 1772 KB Output is correct
16 Correct 64 ms 12672 KB Output is correct
17 Correct 20 ms 2668 KB Output is correct
18 Correct 15 ms 1516 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 2 ms 620 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 400 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct