답안 #913914

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
913914 2024-01-20T13:35:29 Z dsyz Martian DNA (BOI18_dna) C++17
100 / 100
112 ms 13392 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAXN (1000005)
int main() {
	ios_base::sync_with_stdio(false);cin.tie(0);
	ll N,K,R;
	cin>>N>>K>>R;
	ll arr[N];
	for(ll i = 0;i < N;i++){
		cin>>arr[i];		
	}
	ll cnt[K];
	memset(cnt,0,sizeof(cnt));
	ll atleast[K];
	memset(atleast,0,sizeof(atleast));
	set<pair<ll,ll> > shortage;
	for(ll i = 0;i < R;i++){
		ll b,q;
		cin>>b>>q;
		atleast[b] = q;
		shortage.insert({q,b});
	}
	ll minimum = 1e18;
	ll l = 0;
	for(ll r = 0;r < N;r++){
		if(cnt[arr[r]] < atleast[arr[r]]){
			auto it = shortage.find({atleast[arr[r]] - cnt[arr[r]],arr[r]});
			shortage.erase(it);
			cnt[arr[r]]++;
			if(cnt[arr[r]] < atleast[arr[r]]){
				shortage.insert({atleast[arr[r]] - cnt[arr[r]],arr[r]});
			}
		}else{
			cnt[arr[r]]++;
		}
		if(shortage.empty()){
			while(l < r && cnt[arr[l]] > atleast[arr[l]]){
				cnt[arr[l]]--;
				l++;
			}
			minimum = min(minimum,r - l + 1);
		}
	}
	if(!shortage.empty()) cout<<"impossible"<<'\n';
	else cout<<minimum<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 2396 KB Output is correct
2 Correct 12 ms 2396 KB Output is correct
3 Correct 11 ms 2396 KB Output is correct
4 Correct 13 ms 2396 KB Output is correct
5 Correct 14 ms 4188 KB Output is correct
6 Correct 24 ms 2412 KB Output is correct
7 Correct 10 ms 2396 KB Output is correct
8 Correct 16 ms 6236 KB Output is correct
9 Correct 12 ms 3020 KB Output is correct
10 Correct 15 ms 2396 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 10068 KB Output is correct
2 Correct 50 ms 8280 KB Output is correct
3 Correct 24 ms 5464 KB Output is correct
4 Correct 10 ms 2396 KB Output is correct
5 Correct 112 ms 10748 KB Output is correct
6 Correct 85 ms 13392 KB Output is correct
7 Correct 35 ms 3404 KB Output is correct
8 Correct 37 ms 4464 KB Output is correct
9 Correct 13 ms 2396 KB Output is correct
10 Correct 12 ms 2396 KB Output is correct
11 Correct 11 ms 2388 KB Output is correct
12 Correct 14 ms 2396 KB Output is correct
13 Correct 15 ms 4188 KB Output is correct
14 Correct 22 ms 2396 KB Output is correct
15 Correct 9 ms 2396 KB Output is correct
16 Correct 22 ms 6220 KB Output is correct
17 Correct 12 ms 2908 KB Output is correct
18 Correct 15 ms 2396 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 464 KB Output is correct
24 Correct 1 ms 460 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 656 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct