Submission #798026

# Submission time Handle Problem Language Result Execution time Memory
798026 2023-07-30T09:47:06 Z sentheta Martian DNA (BOI18_dna) C++17
100 / 100
47 ms 15688 KB
// author : sentheta aka vanwij
#ifdef VANWIJ
	#include"/home/user/code/bits/stdc++.h"
	#define DBG 1
#else
	#include"bits/stdc++.h"
	#define DBG 0
#endif
using namespace std;

#define Int long long
#define V vector
#define pii pair<int,int>
#define ff first
#define ss second

static mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

#define pow2(x) (1LL<<(x))
#define msb(x) (63-__builtin_clzll(x))
#define bitcnt(x) (__builtin_popcountll(x))

#define nl '\n'
#define _ << ' ' <<
#define all(x) (x).begin(), (x).end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)

#define cerr if(DBG) cout
#define dbg(x) {cerr << "?" << #x << " : " << (x) << endl << flush;}

#define int long long
// const Int MOD = 1e9+7;
const Int MOD = 998244353;
Int bpow(Int a,Int b){
	Int ret = 1;
	for(;b; a=a*a%MOD,b/=2) if(b&1) ret = ret*a%MOD;
	return ret;
}
Int inv(Int a){return bpow(a,MOD-2);}

void solve(); int TC, ALLTC;
signed main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed << setprecision(7);
	// cin >> ALLTC; for(TC=1; TC<=ALLTC; TC++) solve(); return 0;
	solve();
}










const int N = 2e5+5;

int n, k, q;

int a[N];
int ptr[N];
V<int> pos[N];

void solve(){
	
	cin >> n >> k >> q;
	
	rep(i,0,n){
		cin >> a[i];
		
		pos[a[i]].push_back(i);
	}
	
	rep(i,0,k){
		ptr[i] = -1;
	}
	rep(i,0,q){
		int x, y;
		cin >> x >> y;
		ptr[x] = y-1;
	}
	
	int r = 0;
	rep(i,0,k) if(ptr[i]>=0){
		if((int)pos[i].size() <= ptr[i]){
			cout << "impossible" << nl; return;
		}
		
		r = max(r, pos[i][ptr[i]]);
	}
	
	int ans = n;
	rep(l,0,n){
		dbg(l);
		dbg(r);
		ans = min(ans, r-l+1);
		
		ptr[a[l]]++;
		if((int)pos[a[l]].size() <= ptr[a[l]]){
			break;
		}
		r = max(r, pos[a[l]][ptr[a[l]]]);
	}
	
	cout << ans << nl;
	
	
	
	
	
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 5036 KB Output is correct
5 Correct 2 ms 5032 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5040 KB Output is correct
2 Correct 4 ms 5076 KB Output is correct
3 Correct 4 ms 5076 KB Output is correct
4 Correct 3 ms 5204 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 2 ms 5076 KB Output is correct
7 Correct 2 ms 5036 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 ms 5036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 8744 KB Output is correct
2 Correct 13 ms 9180 KB Output is correct
3 Correct 12 ms 8868 KB Output is correct
4 Correct 13 ms 8868 KB Output is correct
5 Correct 26 ms 11364 KB Output is correct
6 Correct 12 ms 9016 KB Output is correct
7 Correct 12 ms 9000 KB Output is correct
8 Correct 33 ms 15588 KB Output is correct
9 Correct 21 ms 10084 KB Output is correct
10 Correct 12 ms 8984 KB Output is correct
11 Correct 2 ms 5076 KB Output is correct
12 Correct 3 ms 5040 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
14 Correct 3 ms 5204 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 3 ms 5076 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 2 ms 4948 KB Output is correct
23 Correct 2 ms 4948 KB Output is correct
24 Correct 2 ms 4948 KB Output is correct
25 Correct 2 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 12020 KB Output is correct
2 Correct 34 ms 11644 KB Output is correct
3 Correct 29 ms 11360 KB Output is correct
4 Correct 12 ms 8812 KB Output is correct
5 Correct 47 ms 13280 KB Output is correct
6 Correct 43 ms 15688 KB Output is correct
7 Correct 21 ms 10072 KB Output is correct
8 Correct 27 ms 10704 KB Output is correct
9 Correct 12 ms 8800 KB Output is correct
10 Correct 12 ms 9228 KB Output is correct
11 Correct 13 ms 8908 KB Output is correct
12 Correct 12 ms 8836 KB Output is correct
13 Correct 26 ms 11312 KB Output is correct
14 Correct 12 ms 8988 KB Output is correct
15 Correct 13 ms 9044 KB Output is correct
16 Correct 33 ms 15648 KB Output is correct
17 Correct 25 ms 10068 KB Output is correct
18 Correct 12 ms 8964 KB Output is correct
19 Correct 3 ms 5076 KB Output is correct
20 Correct 2 ms 5040 KB Output is correct
21 Correct 3 ms 5076 KB Output is correct
22 Correct 3 ms 5172 KB Output is correct
23 Correct 3 ms 5076 KB Output is correct
24 Correct 3 ms 5040 KB Output is correct
25 Correct 2 ms 4948 KB Output is correct
26 Correct 2 ms 4948 KB Output is correct
27 Correct 2 ms 4948 KB Output is correct
28 Correct 2 ms 4952 KB Output is correct
29 Correct 2 ms 5040 KB Output is correct
30 Correct 2 ms 4948 KB Output is correct
31 Correct 2 ms 4948 KB Output is correct
32 Correct 2 ms 4948 KB Output is correct
33 Correct 2 ms 4948 KB Output is correct