Submission #780199

# Submission time Handle Problem Language Result Execution time Memory
780199 2023-07-12T07:13:29 Z Cookie Martian DNA (BOI18_dna) C++14
100 / 100
27 ms 4556 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("VNOICUP.INP");
ofstream fout("VNOICUP.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
using u128 = __uint128_t;
//const int x[4] = {1, -1, 0, 0};
//const int y[4] = {0, 0, 1, -1};
const ll mod = 998244353;
const int mxn = 2e5 + 5, mxq = 2e5 + 5, sq = 400, mxv = 2e7 + 5;
//const int base = (1 << 18);
const ll inf = 1e9, neg = -69420;
int n, k, r, cnt;
int cc[mxn + 1], a[mxn + 1], val[mxn + 1];
void add(int x){
    cc[a[x]]++;
    if(val[a[x]] && cc[a[x]] == val[a[x]])cnt++;
}
void rem(int x){
    if(val[a[x]] && cc[a[x]] == val[a[x]])cnt--;
    cc[a[x]]--;
}
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> k >> r;
    for(int i = 1; i <= n; i++)cin >> a[i];
    for(int i = 0; i < r; i++){
        int id, v; cin >> id >> v; assert(v);
        val[id] = max(val[id], v);
    }
    
    cnt = k - r;
    int rp = 1, ans = inf;
    for(int i = 1; i <= n; i++){
        while(rp <= i)add(rp++);
        if(i > 1){
            rem(i - 1);
        }
            while(cnt < k && rp <= n){
                add(rp++);
                
            }
        
        if(cnt == k)ans = min(ans, rp - i);
    }
    
    if(ans == inf){
      
        cout << "impossible";
    }else{
        cout << ans;
    }
    return(0);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 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 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 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 336 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1164 KB Output is correct
2 Correct 16 ms 1492 KB Output is correct
3 Correct 11 ms 1536 KB Output is correct
4 Correct 10 ms 1436 KB Output is correct
5 Correct 14 ms 2516 KB Output is correct
6 Correct 14 ms 1404 KB Output is correct
7 Correct 11 ms 1632 KB Output is correct
8 Correct 25 ms 3188 KB Output is correct
9 Correct 12 ms 2076 KB Output is correct
10 Correct 15 ms 1480 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 376 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 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 340 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 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 1780 KB Output is correct
2 Correct 19 ms 3148 KB Output is correct
3 Correct 16 ms 2868 KB Output is correct
4 Correct 11 ms 1432 KB Output is correct
5 Correct 25 ms 4052 KB Output is correct
6 Correct 27 ms 4556 KB Output is correct
7 Correct 13 ms 2136 KB Output is correct
8 Correct 16 ms 2388 KB Output is correct
9 Correct 9 ms 1492 KB Output is correct
10 Correct 10 ms 1492 KB Output is correct
11 Correct 11 ms 1536 KB Output is correct
12 Correct 10 ms 1420 KB Output is correct
13 Correct 14 ms 2508 KB Output is correct
14 Correct 15 ms 1520 KB Output is correct
15 Correct 11 ms 1700 KB Output is correct
16 Correct 16 ms 3168 KB Output is correct
17 Correct 13 ms 2032 KB Output is correct
18 Correct 9 ms 1500 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 336 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct