#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int N, K, R, temp1,temp2;
cin >> N >> K >> R;
vector<int>strand(N);
vector<int>requirements(K);
vector<queue<int>>positions(K);
vector<int>nummet(K);
int reqmet = K;
fill(requirements.begin(),requirements.end(),0);
fill(nummet.begin(),nummet.end(),0);
for (int a = 0; a < N; a++)
{
cin >> strand[a];
}
for (int a = 0; a < R; a++)
{
cin >> temp1 >> temp2; //type, need
requirements[temp1] = temp2;
reqmet--;
}
vector<int>requirementscopy(requirements.begin(),requirements.end());
queue<pair<int,int>>tracker; //position, dna type
/*cout << "outputting requirements:\n";
for (int a = 0 ; a < K; a++)
{
cout << requirements[a] << " ";
}
cout << "\n";*/
if (R == 0) //no requirements, sui bian ni! :D
{
cout << 0;
return 0;
}
int currdna, ans = LLONG_MAX;
for (int a = 0; a < N; a++)
{
currdna = strand[a];
if (!requirementscopy[currdna]) //if you dont need that dna
{
continue;
}
if (requirements[currdna] == 1) //just hit the needed goal!
{
//cout << "met requirement for " << currdna << " at " << a << "\n";
reqmet++;
}
requirements[currdna]--;
positions[currdna].push(a); //if you go over the required amount, cut out the first one
nummet[currdna] ++;
tracker.push(make_pair(a,currdna));
if (nummet[currdna] > requirementscopy[currdna]) //youve met mroe than u need
{
positions[currdna].pop();
}
//checking :)
if (reqmet == K)
{
while (tracker.front().first != (positions[tracker.front().second].front()))
{
tracker.pop();
}
ans = min(ans, (a - tracker.front().first + 1));
}
}
/*for (int a = 0 ; a < K; a++)
{
cout << a << " : \n";
while(!positions[a].empty())
{
cout << positions[a].front() << " ";
positions[a].pop();
}
cout << "\n";
}
cout << "\n";*/
if (ans == LLONG_MAX)
{
cout << "impossible";
}
else
{
cout << ans;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
2140 KB |
Output is correct |
4 |
Correct |
2 ms |
3164 KB |
Output is correct |
5 |
Correct |
1 ms |
1372 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
4700 KB |
Output is correct |
2 |
Correct |
11 ms |
3420 KB |
Output is correct |
3 |
Correct |
11 ms |
2396 KB |
Output is correct |
4 |
Correct |
11 ms |
3932 KB |
Output is correct |
5 |
Correct |
47 ms |
58708 KB |
Output is correct |
6 |
Correct |
12 ms |
7340 KB |
Output is correct |
7 |
Correct |
10 ms |
3028 KB |
Output is correct |
8 |
Correct |
76 ms |
142420 KB |
Output is correct |
9 |
Correct |
14 ms |
8540 KB |
Output is correct |
10 |
Correct |
11 ms |
4356 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
2140 KB |
Output is correct |
14 |
Correct |
2 ms |
3164 KB |
Output is correct |
15 |
Correct |
1 ms |
1616 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
460 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
60764 KB |
Output is correct |
2 |
Correct |
59 ms |
46232 KB |
Output is correct |
3 |
Correct |
40 ms |
45416 KB |
Output is correct |
4 |
Correct |
10 ms |
2392 KB |
Output is correct |
5 |
Correct |
65 ms |
76400 KB |
Output is correct |
6 |
Correct |
91 ms |
131188 KB |
Output is correct |
7 |
Correct |
19 ms |
11608 KB |
Output is correct |
8 |
Correct |
27 ms |
19284 KB |
Output is correct |
9 |
Correct |
10 ms |
4700 KB |
Output is correct |
10 |
Correct |
11 ms |
3420 KB |
Output is correct |
11 |
Correct |
11 ms |
2392 KB |
Output is correct |
12 |
Correct |
11 ms |
3944 KB |
Output is correct |
13 |
Correct |
40 ms |
58708 KB |
Output is correct |
14 |
Correct |
13 ms |
7260 KB |
Output is correct |
15 |
Correct |
10 ms |
2908 KB |
Output is correct |
16 |
Correct |
75 ms |
142420 KB |
Output is correct |
17 |
Correct |
14 ms |
8540 KB |
Output is correct |
18 |
Correct |
11 ms |
4224 KB |
Output is correct |
19 |
Correct |
1 ms |
504 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
2256 KB |
Output is correct |
22 |
Correct |
2 ms |
3164 KB |
Output is correct |
23 |
Correct |
1 ms |
1372 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
600 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
452 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |