답안 #518867

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
518867 2022-01-25T01:27:08 Z Ierus Martian DNA (BOI18_dna) C++17
68 / 100
48 ms 11684 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], pref[N][12], need[12], type[12];
int main(){const auto solve=[&]() -> void{
	cin >> n >> k >> r;
	for(int i = 1; i <= n; ++i){
		cin >> a[i];
//		cerr << i << " -> " << a[i] << '\n';
	}
	for(int i = 0; i < r; ++i){
		int id, val;
		cin >> id >> val;
		type[i] = id;
		need[i] = val;
	}
	for(int i = 1; i <= n; ++i){
		for(int j = 0; j < r; ++j){
			pref[i][j] = pref[i-1][j] + (a[i] == type[j]);
		}
	}
//	cerr << "need\n";
//	for(int i = 0; i < k; ++i){
//		cerr << i << " -> " << need[i] << '\n';
//	}
//	cerr << "pref\n";
//	for(int i = 0; i < k; ++i){
//		cerr << "i: " << i << '\n';
//		for(int j = 1; j <= n; ++j){
//			cerr << pref[j][i] << ' ';
//		}cerr << '\n';
//	}
	auto check = [&](int L, int R) -> bool{
		for(int j = 0; j < r; ++j){
			if(pref[R][j] - pref[L-1][j] < need[j]){
				return false;
			}
		}
		return true;
	};
	int res = INT_MAX;
	for(int i = 1; i <= n; ++i){
		int L = i, R = n, ans = -1;
		while(L <= R){
			int M = (L + R) / 2;
//			cerr << "L: " << L << " R: " << R << " M: " << M << '\n';
			if(check(i, M)){
				R = (ans = M) - 1;
			}else L = M + 1;
		}
//		cerr << i << " -> " << ans << '\n';	
//		cerr << " changed " << res << '\n';
		if(ans != -1){
			res = min(res, ans - i + 1);
		}
	}
	if(res == INT_MAX) cout << "impossible";
	else cout << res;
};NFS;int T=1;if(I)cin>>T;while(T--)solve();}









# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 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 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 10476 KB Output is correct
2 Correct 27 ms 10444 KB Output is correct
3 Correct 48 ms 10448 KB Output is correct
4 Correct 35 ms 10412 KB Output is correct
5 Correct 44 ms 10408 KB Output is correct
6 Correct 19 ms 10832 KB Output is correct
7 Correct 24 ms 10944 KB Output is correct
8 Correct 44 ms 11684 KB Output is correct
9 Correct 43 ms 11344 KB Output is correct
10 Correct 38 ms 10852 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
12 Correct 1 ms 464 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 0 ms 216 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 320 KB Output is correct
23 Correct 0 ms 336 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 32 ms 10456 KB Output isn't correct
2 Halted 0 ms 0 KB -