답안 #862878

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
862878 2023-10-19T07:44:45 Z iskhakkutbilim Martian DNA (BOI18_dna) C++17
100 / 100
28 ms 5844 KB
#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define all(a) a.begin(), a.end()
const int N = 2e5;

int n, k, q;
vector<int> a;
vector<pair<int, int> > query;
int nuk[N+10], need[N + 10];



main(){
   ios::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
	cin >> n >> k >> q;
	a.resize(n);
	for(int i = 0;i < n; i++){
		cin >> a[i];
		nuk[a[i]]++;
	}
	for(int i = 0;i < q; i++){
		int c, cnt; cin >> c >> cnt;
		query.push_back({c, cnt});
		need[c] = cnt;
	}
	for(auto [c, cnt] : query){
		if(nuk[c] < cnt){
			cout << "impossible";
			return 0;
		}
	}
	for(int i = 0;i < n; i++) nuk[a[i]] = 0;
	int ans = n, ok = 0;
	for(int l = 0, r = 0; l < n; l++){
		while(r < n && ok < q){
			nuk[a[r]]++;
			if(nuk[a[r]] == need[a[r]]){
				ok++;
			}
			r++;
		}
		if(ok > q) assert(false);
		if(ok == q){
			ans = min(ans, r - l);
		}
		if(nuk[a[l]] == need[a[l]]){
			ok--;
		}
		nuk[a[l]]--;
	}
	cout << ans;
	return 0;
}

Compilation message

dna.cpp:16:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   16 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 464 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 480 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 472 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1636 KB Output is correct
2 Correct 10 ms 1628 KB Output is correct
3 Correct 11 ms 1500 KB Output is correct
4 Correct 10 ms 1628 KB Output is correct
5 Correct 13 ms 2652 KB Output is correct
6 Correct 9 ms 1624 KB Output is correct
7 Correct 9 ms 1760 KB Output is correct
8 Correct 15 ms 3164 KB Output is correct
9 Correct 12 ms 2140 KB Output is correct
10 Correct 12 ms 1628 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 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 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 544 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 472 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 460 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 4560 KB Output is correct
2 Correct 20 ms 3700 KB Output is correct
3 Correct 17 ms 3420 KB Output is correct
4 Correct 10 ms 1632 KB Output is correct
5 Correct 22 ms 5328 KB Output is correct
6 Correct 28 ms 5844 KB Output is correct
7 Correct 13 ms 2396 KB Output is correct
8 Correct 15 ms 2732 KB Output is correct
9 Correct 9 ms 1628 KB Output is correct
10 Correct 10 ms 1628 KB Output is correct
11 Correct 11 ms 1628 KB Output is correct
12 Correct 12 ms 1628 KB Output is correct
13 Correct 17 ms 2652 KB Output is correct
14 Correct 9 ms 1628 KB Output is correct
15 Correct 10 ms 1628 KB Output is correct
16 Correct 16 ms 3164 KB Output is correct
17 Correct 12 ms 2252 KB Output is correct
18 Correct 9 ms 1628 KB Output is correct
19 Correct 1 ms 344 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 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct