Submission #768313

# Submission time Handle Problem Language Result Execution time Memory
768313 2023-06-27T22:29:35 Z Yell0 Martian DNA (BOI18_dna) C++17
100 / 100
68 ms 9236 KB
#include <bits/stdc++.h>

using namespace std;
const int MN=2e5+2;
int N,K,R,d[MN],req[MN],f[MN];

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  cin>>N>>K>>R;
  for(int i=1;i<=N;++i) cin>>d[i];
  set<int> needs;
  for(int i=1;i<=R;++i) {
    int b,q;
    cin>>b>>q;
    req[b]=q;
    needs.insert(b);
  }
  int l=1,r=1;
  for(;r<=N;++r) {
    if(needs.empty()) break;
    if(++f[d[r]]==req[d[r]]) needs.erase(d[r]);
  }
  if(r>N&&needs.size()) {
    cout<<"impossible\n";
    return 0;
  }
  int ans=r-l;
  for(;l<=N;++l) {
    --f[d[l]];
    while(f[d[l]]<req[d[l]]) {
      if(r>N) {
        cout<<ans<<'\n';
        return 0;
      }
      ++f[d[r]];
      ++r;
    }
    ans=min(ans,r-l-1);
  }
  cout<<ans<<'\n';
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 324 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 340 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 212 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 328 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1108 KB Output is correct
2 Correct 10 ms 1400 KB Output is correct
3 Correct 10 ms 1480 KB Output is correct
4 Correct 9 ms 1408 KB Output is correct
5 Correct 12 ms 2488 KB Output is correct
6 Correct 8 ms 1492 KB Output is correct
7 Correct 12 ms 1624 KB Output is correct
8 Correct 18 ms 3160 KB Output is correct
9 Correct 11 ms 2072 KB Output is correct
10 Correct 9 ms 1448 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 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 328 KB Output is correct
22 Correct 1 ms 320 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 5492 KB Output is correct
2 Correct 40 ms 5980 KB Output is correct
3 Correct 23 ms 3768 KB Output is correct
4 Correct 12 ms 1492 KB Output is correct
5 Correct 40 ms 7800 KB Output is correct
6 Correct 68 ms 9236 KB Output is correct
7 Correct 14 ms 2516 KB Output is correct
8 Correct 20 ms 3132 KB Output is correct
9 Correct 9 ms 1388 KB Output is correct
10 Correct 10 ms 1456 KB Output is correct
11 Correct 10 ms 1492 KB Output is correct
12 Correct 9 ms 1492 KB Output is correct
13 Correct 13 ms 2516 KB Output is correct
14 Correct 11 ms 1388 KB Output is correct
15 Correct 9 ms 1620 KB Output is correct
16 Correct 15 ms 3128 KB Output is correct
17 Correct 11 ms 2024 KB Output is correct
18 Correct 9 ms 1484 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 336 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 212 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 212 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 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct