Submission #519708

# Submission time Handle Problem Language Result Execution time Memory
519708 2022-01-27T05:06:12 Z Ierus Martian DNA (BOI18_dna) C++17
100 / 100
32 ms 3144 KB
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("unroll-loops,Ofast,O3")
#pragma GCC target("avx,avx2,fma")
#define F first
#define S second
#define sz(x) (int)x.size()
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define NFS ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
typedef long long ll;
//random_device(rd);
//mt19937 rng(rd());
//const long long FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
//template<class T> T randomize(T mod){
//	return (uniform_int_distribution<T>(0, mod))(rng);
//}

const int E = 1e6+777;
const long long inf = 1e18+777;
const int N = 2e5+777;
const int MOD = 1e9+7;
const bool I = 0;
int n, k, r, a[N], need[N], have[N], sum;
int main(){const auto solve=[&]() -> void{
	cin >> n >> k >> r;
	for(int i = 1; i <= n; ++i){
		cin >> a[i];
	}
	for(int i = 0; i < r; ++i){
		int id, val;
		cin >> id >> val;
		need[id] = val;
	}
	int R = 0, res = INT_MAX;
	for(int L = 1; L <= n; ++L){
		while(R < L - 1){
			if(need[a[R]] == have[a[R]]){
				--sum;
			}
			--have[R];
			++R;
		}
		while(sum < r && R + 1 <= n){
			++R;
			++have[a[R]];
			if(need[a[R]] == have[a[R]]){
				++sum;	
			}
//			cerr << "R: " << R << " have["<<a[R]<<"]: " << have[a[R]]  << " sum: " << sum << '\n';
		}
		if(sum == r)
			res = min(res, R - L + 1);
//		cerr << "L: " << L << " R: " << R << " sum: " << sum << '\n';
		if(need[a[L]] == have[a[L]]){
			--sum;
		}
		--have[a[L]];
	}
	if(res == INT_MAX) cout << "impossible";
	else cout << res;
};NFS;int T=1;if(I)cin>>T;while(T--)solve();}










# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1032 KB Output is correct
2 Correct 12 ms 1052 KB Output is correct
3 Correct 17 ms 1032 KB Output is correct
4 Correct 12 ms 1100 KB Output is correct
5 Correct 15 ms 1356 KB Output is correct
6 Correct 11 ms 1100 KB Output is correct
7 Correct 12 ms 1040 KB Output is correct
8 Correct 17 ms 1884 KB Output is correct
9 Correct 14 ms 1100 KB Output is correct
10 Correct 11 ms 1048 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 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 1688 KB Output is correct
2 Correct 24 ms 1484 KB Output is correct
3 Correct 27 ms 1560 KB Output is correct
4 Correct 10 ms 1028 KB Output is correct
5 Correct 32 ms 1872 KB Output is correct
6 Correct 31 ms 2500 KB Output is correct
7 Correct 22 ms 1144 KB Output is correct
8 Correct 19 ms 1264 KB Output is correct
9 Correct 12 ms 1072 KB Output is correct
10 Correct 11 ms 1028 KB Output is correct
11 Correct 12 ms 1528 KB Output is correct
12 Correct 11 ms 1468 KB Output is correct
13 Correct 16 ms 2564 KB Output is correct
14 Correct 13 ms 1432 KB Output is correct
15 Correct 13 ms 1616 KB Output is correct
16 Correct 20 ms 3144 KB Output is correct
17 Correct 16 ms 1996 KB Output is correct
18 Correct 12 ms 1400 KB Output is correct
19 Correct 1 ms 324 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 324 KB Output is correct
26 Correct 0 ms 336 KB Output is correct
27 Correct 1 ms 324 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 208 KB Output is correct
30 Correct 0 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct