Submission #780180

# Submission time Handle Problem Language Result Execution time Memory
780180 2023-07-12T07:08:54 Z Cookie Martian DNA (BOI18_dna) C++14
0 / 100
20 ms 1672 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;
        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);
        }else{
            while(cnt != k && rp <= n){
                add(rp++);
                
            }
        }
        if(cnt == k)ans = min(ans, rp - i);
    }
    assert(ans > 0);
    if(ans == inf){
        assert(0);
        cout << "impossible";
    }else{
        cout << ans;
    }
    return(0);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 1108 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 1672 KB Output isn't correct
2 Halted 0 ms 0 KB -