# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
579014 |
2022-06-18T09:51:38 Z |
ddy888 |
Martian DNA (BOI18_dna) |
C++17 |
|
82 ms |
9304 KB |
#undef _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define fi first
#define si second
typedef pair<int,int> pi;
typedef tuple<int,int,int> ti;
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MAXN = 200010, INF = 2e9;
int n, k, r;
int arr[MAXN];
int req[MAXN];
int cnt[MAXN];
set<int> bases;
int ans = INF;
void remove(int i) {
if (!req[arr[i]]) return;
--cnt[arr[i]];
if (cnt[arr[i]] < req[arr[i]]) {
if (*bases.lower_bound(arr[i]) == arr[i]) bases.erase(arr[i]);
}
}
void add(int i) {
if (!req[arr[i]]) return;
++cnt[arr[i]];
if (cnt[arr[i]] >= req[arr[i]]) bases.insert(arr[i]);
}
bool check(int i) {
if (!req[arr[i]]) return true;
return (cnt[arr[i]] > req[arr[i]]);
}
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> k >> r;
for (int i = 1; i <= n; ++i) cin >> arr[i];
for (int i = 1; i <= r; ++i) {
int x, y; cin >> x >> y;
req[x] = y;
}
int l = 1;
for (int i = 1; i <= n; ++i) {
add(i);
if ((int)bases.size() == r) {
while (l < i && check(l)) {
remove(l);
++l;
}
ans = min(ans, i - l + 1);
}
}
if (ans == INF) cout << "impossible";
else cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
368 KB |
Output is correct |
5 |
Correct |
1 ms |
356 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
1108 KB |
Output is correct |
2 |
Correct |
12 ms |
1520 KB |
Output is correct |
3 |
Correct |
15 ms |
1512 KB |
Output is correct |
4 |
Correct |
14 ms |
1492 KB |
Output is correct |
5 |
Correct |
16 ms |
2244 KB |
Output is correct |
6 |
Correct |
16 ms |
1496 KB |
Output is correct |
7 |
Correct |
13 ms |
1636 KB |
Output is correct |
8 |
Correct |
21 ms |
2444 KB |
Output is correct |
9 |
Correct |
19 ms |
2036 KB |
Output is correct |
10 |
Correct |
14 ms |
1516 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
352 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
328 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
328 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
82 ms |
5376 KB |
Output is correct |
2 |
Correct |
54 ms |
5916 KB |
Output is correct |
3 |
Correct |
29 ms |
3796 KB |
Output is correct |
4 |
Correct |
17 ms |
1424 KB |
Output is correct |
5 |
Correct |
31 ms |
4044 KB |
Output is correct |
6 |
Correct |
77 ms |
9304 KB |
Output is correct |
7 |
Correct |
35 ms |
2508 KB |
Output is correct |
8 |
Correct |
37 ms |
3108 KB |
Output is correct |
9 |
Correct |
12 ms |
1492 KB |
Output is correct |
10 |
Correct |
12 ms |
1492 KB |
Output is correct |
11 |
Correct |
15 ms |
1492 KB |
Output is correct |
12 |
Correct |
13 ms |
1512 KB |
Output is correct |
13 |
Correct |
20 ms |
2252 KB |
Output is correct |
14 |
Correct |
15 ms |
1432 KB |
Output is correct |
15 |
Correct |
13 ms |
1628 KB |
Output is correct |
16 |
Correct |
26 ms |
2432 KB |
Output is correct |
17 |
Correct |
19 ms |
2000 KB |
Output is correct |
18 |
Correct |
14 ms |
1492 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |