#include<bits/stdc++.h>
using namespace std;
#define int long long
bool debug = false;
signed main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
int n, k, r, temp; cin >> n >> k >> r;
vector<int> v(n);
for (int i = 0 ;i < n; ++i){
cin >> v[i];
}
vector<int> val(k);
for (int i = 0;i < r; ++i){
cin >> temp;
cin >> val[temp];
}
int lo = 0, hi = n, mid = (lo + hi)/2;
while (lo != mid){
if(debug) cout << mid << '\n';
temp = 0;
vector<int> cur(n, 0);
vector<bool> full(k,false);
for (int i = 0; i < mid; ++i){
cur[v[i]]++;
if(cur[v[i]] == val[v[i]]){
full[v[i]] = true;
temp++;
}
}
if(temp == r){
hi = mid;
mid = (lo + hi)/2;
continue;
}
for (int i = mid; i < n; ++i){
cur[v[i]]++;
cur[v[i-mid]]--;
if (v[i] != v[i-mid]){
if(cur[v[i]] == val[v[i]]){
full[v[i]] = true;
temp++;
}
if (cur[v[i-mid]] == val[v[i-mid]]-1){
full[v[i-mid]] = false;
temp--;
}
}
if(temp == r){
hi = mid;
mid = (lo + hi)/2;
continue;
}
}
lo = mid+1;
mid = (lo + hi)/2;
}
if (temp != r && mid == n)cout << "impossible";
else cout << mid;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2083 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2090 ms |
340 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2072 ms |
3412 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
4064 KB |
Output is correct |
2 |
Execution timed out |
2088 ms |
3908 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |