Submission #890908

# Submission time Handle Problem Language Result Execution time Memory
890908 2023-12-22T05:08:23 Z shoryu386 Martian DNA (BOI18_dna) C++17
100 / 100
117 ms 12952 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

main(){
	int n, k, req; cin >> n >> k >> req;
	
	int arr[n];
	for (int x = 0; x < n; x++){
		cin >> arr[x];
	}
	
	int ans = INT_MAX; unordered_set<int> unfulfilled;
	unordered_map<int, int> requires; int a, b;
	for (int x = 0; x < req; x++){
		cin >> a >> b;
		requires[a] = b;
		unfulfilled.insert(a);
	}
	
	int l = 0;
	for (int r = 0; r < n; r++){
		if (requires.count(arr[r])){
			requires[arr[r]]--;
			if (requires[arr[r]] <= 0) unfulfilled.erase(arr[r]);
		}
		
		while (l <= r && unfulfilled.size() == 0){
			if (requires.count(arr[l]) && requires[arr[l]] >= 0){
				break;
			}
			
			if (requires.count(arr[l])) requires[arr[l]]++;
			l++;
		}
		
		if (unfulfilled.size() == 0) ans = min(ans, r-l+1);
	}
	
	if (ans != INT_MAX) cout << ans;
	else cout << "impossible";
}

Compilation message

dna.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    6 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 436 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 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 448 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 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
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 2140 KB Output is correct
2 Correct 41 ms 2140 KB Output is correct
3 Correct 34 ms 2404 KB Output is correct
4 Correct 33 ms 2404 KB Output is correct
5 Correct 47 ms 3124 KB Output is correct
6 Correct 29 ms 2360 KB Output is correct
7 Correct 29 ms 2564 KB Output is correct
8 Correct 50 ms 3156 KB Output is correct
9 Correct 42 ms 2932 KB Output is correct
10 Correct 31 ms 2368 KB Output is correct
11 Correct 1 ms 508 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 2 ms 444 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 436 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 432 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 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 94 ms 9852 KB Output is correct
2 Correct 86 ms 8456 KB Output is correct
3 Correct 60 ms 4640 KB Output is correct
4 Correct 33 ms 2356 KB Output is correct
5 Correct 90 ms 10352 KB Output is correct
6 Correct 117 ms 12952 KB Output is correct
7 Correct 44 ms 3620 KB Output is correct
8 Correct 58 ms 4436 KB Output is correct
9 Correct 30 ms 2136 KB Output is correct
10 Correct 30 ms 2364 KB Output is correct
11 Correct 34 ms 2396 KB Output is correct
12 Correct 30 ms 2396 KB Output is correct
13 Correct 49 ms 3128 KB Output is correct
14 Correct 27 ms 2140 KB Output is correct
15 Correct 29 ms 2392 KB Output is correct
16 Correct 48 ms 3156 KB Output is correct
17 Correct 44 ms 2884 KB Output is correct
18 Correct 42 ms 2140 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 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 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 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 436 KB Output is correct
33 Correct 0 ms 348 KB Output is correct