# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
915866 |
2024-01-24T19:54:17 Z |
n3rm1n |
Martian DNA (BOI18_dna) |
C++17 |
|
24 ms |
4940 KB |
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int MAXN = 2e5 + 10;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int n, k, r;
int a[MAXN], cnt[MAXN], need[MAXN];
int total_need = 0;
void read()
{
cin >> n >> k >> r;
for (int i = 1; i <= n; ++ i)
{
cin >> a[i];
}
int x, wx;
for (int i = 1; i <= r; ++ i)
{
cin >> x >> wx;
total_need += wx;
need[x] = wx;
}
}
void solve()
{
int j = 0;
int were_needed = 0;
for (int i = 1; i <= n && !j; ++ i)
{
if(cnt[a[i]] < need[a[i]])
{
were_needed ++;
}
cnt[a[i]] ++;
if(were_needed == total_need)
j = i;
}
if(were_needed != total_need)
{
cout << "impossible" << endl;
return;
}
int ans = j;
for (int i = 2; i <= n; ++ i)
{
cnt[a[i-1]] --;
if(cnt[a[i-1]] < need[a[i-1]])
{
int ok = 0;
for (int jj = j+1; jj <= n && !ok; ++ jj)
{
cnt[a[jj]] ++;
if(a[jj] == a[i-1])
{
ok = 1;
j = jj;
}
}
if(!ok)break;
}
ans = min(ans, j - i + 1);
}
cout << ans << endl;
}
int main()
{
speed();
read();
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2536 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
2908 KB |
Output is correct |
2 |
Correct |
9 ms |
2908 KB |
Output is correct |
3 |
Correct |
10 ms |
2904 KB |
Output is correct |
4 |
Correct |
9 ms |
3036 KB |
Output is correct |
5 |
Correct |
13 ms |
3664 KB |
Output is correct |
6 |
Correct |
9 ms |
2908 KB |
Output is correct |
7 |
Correct |
10 ms |
3160 KB |
Output is correct |
8 |
Correct |
14 ms |
3796 KB |
Output is correct |
9 |
Correct |
12 ms |
3416 KB |
Output is correct |
10 |
Correct |
9 ms |
2908 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2392 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
4444 KB |
Output is correct |
2 |
Correct |
19 ms |
4188 KB |
Output is correct |
3 |
Correct |
18 ms |
4008 KB |
Output is correct |
4 |
Correct |
11 ms |
2904 KB |
Output is correct |
5 |
Correct |
23 ms |
4940 KB |
Output is correct |
6 |
Correct |
24 ms |
4688 KB |
Output is correct |
7 |
Correct |
13 ms |
3420 KB |
Output is correct |
8 |
Correct |
15 ms |
3676 KB |
Output is correct |
9 |
Correct |
9 ms |
2908 KB |
Output is correct |
10 |
Correct |
9 ms |
2908 KB |
Output is correct |
11 |
Correct |
10 ms |
2908 KB |
Output is correct |
12 |
Correct |
13 ms |
2884 KB |
Output is correct |
13 |
Correct |
12 ms |
3676 KB |
Output is correct |
14 |
Correct |
9 ms |
2908 KB |
Output is correct |
15 |
Correct |
10 ms |
3164 KB |
Output is correct |
16 |
Correct |
15 ms |
3828 KB |
Output is correct |
17 |
Correct |
11 ms |
3400 KB |
Output is correct |
18 |
Correct |
9 ms |
2884 KB |
Output is correct |
19 |
Correct |
1 ms |
2512 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2392 KB |
Output is correct |
23 |
Correct |
1 ms |
2392 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
1 ms |
2648 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2508 KB |
Output is correct |