답안 #642582

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
642582 2022-09-20T06:57:15 Z andreast12 Martian DNA (BOI18_dna) C++17
0 / 100
42 ms 3156 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
const int mod=998244353, maxn=2e5+5;
ll n, k, r, a[maxn], tipe, butuh[maxn], ki, ka, mid, res, unik, cukup, cnt[maxn], x;
bool penting[maxn], bisa;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n >> k >> r;
    for(int i=1; i<=n; i++) cin >> a[i];
    for(int i=1; i<=r; i++) {
        cin >> tipe >> x;
        penting[tipe]=true;
        butuh[tipe]=x;
    }
    ki=k, ka=n, res=-1;
    while(ki<=ka) {
        mid=(ki+ka)/2, bisa=false, unik=cukup=0;
        for(int i=0; i<k; i++) cnt[i]=0;
        for(int i=1; i<=n; i++) {
            if(i>mid) {
                cnt[a[i-mid]]--;
                if(cnt[a[i-mid]]==0) unik--;
                if(penting[a[i-mid]]&&(cnt[a[i-mid]]+1==butuh[a[i-mid]])) cukup--;
            }
            cnt[a[i]]++;
            if(cnt[a[i]]==1) unik++;
            if(penting[a[i]]&&(cnt[a[i]]==butuh[a[i]])) cukup++;
            if(unik==k&&cukup==r) bisa=true;
            // cout << i << ": " << unik << ' ' << cukup << '\n';
        }
        if(bisa) {
            res=mid;
            ka=mid-1;
        } else ki=mid+1;
    }
    if(res==-1) cout << "impossible";
    else cout << res;
    cout << '\n';
}
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 1876 KB Output is correct
2 Correct 37 ms 1876 KB Output is correct
3 Correct 42 ms 1876 KB Output is correct
4 Correct 37 ms 1888 KB Output is correct
5 Incorrect 35 ms 2488 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 39 ms 3156 KB Output isn't correct
2 Halted 0 ms 0 KB -