# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
930091 |
2024-02-18T13:04:16 Z |
Karoot |
Martian DNA (BOI18_dna) |
C++17 |
|
87 ms |
9556 KB |
#include <iostream>
#include <cmath>
#include <unordered_map>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <string>
#include <iomanip>
#include <algorithm>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
typedef long long ll;
ll linf = 1e15+1;
inline void scoobydoobydoo(){
ios::sync_with_stdio(false);
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
const int MAXN = 2e5+1;
int amountOf[MAXN], needed[MAXN];
set<int> fulfilled;
bool nocares[MAXN];
int main(){
scoobydoobydoo();
int n, k, r; cin >> n >> k >> r;
vector<int> v(n);
for (int i = 0; i < n; i++)cin >> v[i];
for (int i = 0; i < r; i++){
int a; cin >> a;
cin >> needed[a];
}
for (int i = 0; i <= k+1; i++){
if (!needed[i])nocares[i] = true;
}
int i = 0, j = 1;
if (!nocares[v[0]]){
amountOf[v[0]]++;
if (amountOf[v[0]] >= needed[v[0]])fulfilled.insert(v[0]);
}
int mini = 1e7+1;;
while (i < j){
if (j == n || fulfilled.size() == r){
//cout << "______________________________" << endl;
if (fulfilled.size() == r) mini = min(mini, j-i);
if (!nocares[v[i]]){
amountOf[v[i]]--;
if (amountOf[v[i]] < needed[v[i]]){
auto it = fulfilled.find(v[i]);
if (it != fulfilled.end() && (*it) == v[i]){
fulfilled.erase(it);
}
}
}
i++;
} else {
//cout << ".,................................ " << endl;
if (!nocares[v[j]]){
amountOf[v[j]]++;
if (amountOf[v[j]] >= needed[v[j]])fulfilled.insert(v[j]);
}
j++;
}
/*//cout << i << " " << j << endl;
for (auto e : fulfilled)cout << e << endl;
for (int i = 0; i < k; i++){
if (!nocares[i])cout << i << ": " << amountOf[i] << ", ";
}
cout << endl;*/
}
if (mini > 1e6)cout << "impossible" << endl;
else cout << mini << endl;
return 0;
}
Compilation message
dna.cpp: In function 'int main()':
dna.cpp:58:40: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
58 | if (j == n || fulfilled.size() == r){
| ~~~~~~~~~~~~~~~~~^~~~
dna.cpp:60:34: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
60 | if (fulfilled.size() == r) mini = min(mini, j-i);
| ~~~~~~~~~~~~~~~~~^~~~
# |
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 |
408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 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 |
472 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
1884 KB |
Output is correct |
2 |
Correct |
13 ms |
1628 KB |
Output is correct |
3 |
Correct |
17 ms |
1508 KB |
Output is correct |
4 |
Correct |
17 ms |
1628 KB |
Output is correct |
5 |
Correct |
13 ms |
2396 KB |
Output is correct |
6 |
Correct |
9 ms |
1628 KB |
Output is correct |
7 |
Correct |
10 ms |
1628 KB |
Output is correct |
8 |
Correct |
16 ms |
2784 KB |
Output is correct |
9 |
Correct |
12 ms |
2140 KB |
Output is correct |
10 |
Correct |
12 ms |
1628 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
348 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 |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 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 |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
7268 KB |
Output is correct |
2 |
Correct |
74 ms |
5972 KB |
Output is correct |
3 |
Correct |
31 ms |
3920 KB |
Output is correct |
4 |
Correct |
11 ms |
1628 KB |
Output is correct |
5 |
Correct |
27 ms |
4076 KB |
Output is correct |
6 |
Correct |
68 ms |
9556 KB |
Output is correct |
7 |
Correct |
27 ms |
2648 KB |
Output is correct |
8 |
Correct |
33 ms |
3148 KB |
Output is correct |
9 |
Correct |
13 ms |
1624 KB |
Output is correct |
10 |
Correct |
13 ms |
1628 KB |
Output is correct |
11 |
Correct |
17 ms |
1700 KB |
Output is correct |
12 |
Correct |
15 ms |
1644 KB |
Output is correct |
13 |
Correct |
13 ms |
2396 KB |
Output is correct |
14 |
Correct |
9 ms |
1624 KB |
Output is correct |
15 |
Correct |
10 ms |
1628 KB |
Output is correct |
16 |
Correct |
15 ms |
2652 KB |
Output is correct |
17 |
Correct |
16 ms |
2136 KB |
Output is correct |
18 |
Correct |
15 ms |
1628 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
432 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
472 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |