# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1111273 | 2024-11-12T01:03:03 Z | tuannm | Martian DNA (BOI18_dna) | C++17 | 23 ms | 2816 KB |
#include<bits/stdc++.h> #define ii pair<int, int> #define ll pair<long long, long long> #define fi first #define se second #define pb push_back using namespace std; const int mod[2] = {1000000007, 998244353}; const int N = 2e5 + 1; const string NAME = ""; int n, k, r, cnt[N], a[N], needed[N]; void inp(){ cin >> n >> k >> r; for(int i = 1; i <= n; ++i) cin >> a[i], needed[a[i]] = n + 1; for(int i = 1; i <= r; ++i){ int b, q; cin >> b >> q; needed[b] = q; } } void solve(){ int j = 0, cntFulfill = 0, ans = n + 1; for(int i = 1; i <= n; ++i){ while(j < n && cntFulfill < r){ ++j; ++cnt[a[j]]; cntFulfill += (cnt[a[j]] == needed[a[j]]); } if(cntFulfill == r) ans = min(ans, j - i + 1); cntFulfill -= (cnt[a[i]] == needed[a[i]]); --cnt[a[i]]; } if(ans == n + 1) return (void) (cout << "impossible"); cout << ans; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen((NAME + ".inp").c_str(), "r")){ freopen((NAME + ".inp").c_str(), "r", stdin); freopen((NAME + ".out").c_str(), "w", stdout); } inp(); solve(); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 504 KB | Output is correct |
4 | Correct | 1 ms | 336 KB | Output is correct |
5 | Correct | 1 ms | 336 KB | Output is correct |
6 | Correct | 1 ms | 336 KB | Output is correct |
7 | Correct | 1 ms | 336 KB | Output is correct |
8 | Correct | 1 ms | 336 KB | Output is correct |
9 | Correct | 1 ms | 336 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
3 | Correct | 1 ms | 336 KB | Output is correct |
4 | Correct | 1 ms | 336 KB | Output is correct |
5 | Correct | 1 ms | 520 KB | Output is correct |
6 | Correct | 1 ms | 336 KB | Output is correct |
7 | Correct | 1 ms | 336 KB | Output is correct |
8 | Correct | 1 ms | 336 KB | Output is correct |
9 | Correct | 1 ms | 336 KB | Output is correct |
10 | Correct | 1 ms | 336 KB | Output is correct |
11 | Correct | 1 ms | 336 KB | Output is correct |
12 | Correct | 1 ms | 336 KB | Output is correct |
13 | Correct | 1 ms | 336 KB | Output is correct |
14 | Correct | 1 ms | 336 KB | Output is correct |
15 | Correct | 1 ms | 336 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 1104 KB | Output is correct |
2 | Correct | 10 ms | 1204 KB | Output is correct |
3 | Correct | 10 ms | 1104 KB | Output is correct |
4 | Correct | 10 ms | 1104 KB | Output is correct |
5 | Correct | 13 ms | 1872 KB | Output is correct |
6 | Correct | 8 ms | 1104 KB | Output is correct |
7 | Correct | 15 ms | 1104 KB | Output is correct |
8 | Correct | 15 ms | 2816 KB | Output is correct |
9 | Correct | 12 ms | 1104 KB | Output is correct |
10 | Correct | 9 ms | 1104 KB | Output is correct |
11 | Correct | 1 ms | 336 KB | Output is correct |
12 | Correct | 1 ms | 336 KB | Output is correct |
13 | Correct | 1 ms | 336 KB | Output is correct |
14 | Correct | 1 ms | 336 KB | Output is correct |
15 | Correct | 1 ms | 336 KB | Output is correct |
16 | Correct | 1 ms | 504 KB | Output is correct |
17 | Correct | 1 ms | 336 KB | Output is correct |
18 | Correct | 1 ms | 336 KB | Output is correct |
19 | Correct | 1 ms | 336 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 | 336 KB | Output is correct |
25 | Correct | 1 ms | 336 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 1872 KB | Output is correct |
2 | Correct | 19 ms | 1816 KB | Output is correct |
3 | Correct | 14 ms | 1616 KB | Output is correct |
4 | Correct | 10 ms | 1120 KB | Output is correct |
5 | Correct | 22 ms | 1900 KB | Output is correct |
6 | Correct | 23 ms | 2640 KB | Output is correct |
7 | Correct | 12 ms | 1272 KB | Output is correct |
8 | Correct | 15 ms | 1360 KB | Output is correct |
9 | Correct | 8 ms | 1076 KB | Output is correct |
10 | Correct | 9 ms | 1104 KB | Output is correct |
11 | Correct | 9 ms | 1184 KB | Output is correct |
12 | Correct | 11 ms | 1104 KB | Output is correct |
13 | Correct | 14 ms | 1740 KB | Output is correct |
14 | Correct | 9 ms | 1276 KB | Output is correct |
15 | Correct | 10 ms | 1264 KB | Output is correct |
16 | Correct | 15 ms | 2784 KB | Output is correct |
17 | Correct | 11 ms | 1104 KB | Output is correct |
18 | Correct | 9 ms | 1104 KB | Output is correct |
19 | Correct | 1 ms | 336 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 | 336 KB | Output is correct |
25 | Correct | 1 ms | 336 KB | Output is correct |
26 | Correct | 1 ms | 336 KB | Output is correct |
27 | Correct | 1 ms | 336 KB | Output is correct |
28 | Correct | 1 ms | 336 KB | Output is correct |
29 | Correct | 1 ms | 336 KB | Output is correct |
30 | Correct | 1 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 |