답안 #675956

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
675956 2022-12-28T15:13:55 Z browntoad Martian DNA (BOI18_dna) C++14
100 / 100
36 ms 5036 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
using namespace std;
#define ll long long
#define int ll
#define FOR(i,a, b) for (int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n+1)
#define pii pair<int, int>
#define SZ(x) (int)((x).size())
#define ALL(x) (x).begin(), (x).end()
#define f first
#define s second
#define pb push_back
 
const ll maxn = 2e5+5;
const ll inf = (1ll<<60);
 
signed main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n, k, r; cin>>n>>k>>r;
    vector<int> req(k), cur(k);
    vector<int> vc(n);
    REP(i, n){
        cin>>vc[i];
    }
    REP(i, r){
        int a, b; cin>>a>>b;
        req[a]=b;
    }
    r=-1;
    int cpos = 0;
    REP(i, n){
        cur[vc[i]]++;
        while(cpos<k&&req[cpos]<=cur[cpos]){
            cpos++;
        }
        if (cpos==k){
            r=i;
            break;
        }
    }
    if (r==-1){
        cout<<"impossible"<<endl;
        return 0;
    }
    int ans=inf;
    cpos=-1;
    REP(i, n){
        ans=min(ans, r-i+1);
        cur[vc[i]]--;
        if (cur[vc[i]]<req[vc[i]]){
            cpos=vc[i];
            r++;
            while(r<n){
                cur[vc[r]]++;
                if (cur[cpos]>=req[cpos]){
                    break;
                }
                r++;
            }
            if (r==n){
                break;
            }
        }
    }
    cout<<ans<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 1896 KB Output is correct
2 Correct 11 ms 1900 KB Output is correct
3 Correct 13 ms 1876 KB Output is correct
4 Correct 12 ms 1896 KB Output is correct
5 Correct 15 ms 3156 KB Output is correct
6 Correct 13 ms 1876 KB Output is correct
7 Correct 10 ms 1904 KB Output is correct
8 Correct 18 ms 4948 KB Output is correct
9 Correct 13 ms 2004 KB Output is correct
10 Correct 12 ms 1876 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 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 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 3148 KB Output is correct
2 Correct 22 ms 2772 KB Output is correct
3 Correct 19 ms 2840 KB Output is correct
4 Correct 18 ms 1876 KB Output is correct
5 Correct 36 ms 3464 KB Output is correct
6 Correct 30 ms 4692 KB Output is correct
7 Correct 14 ms 2020 KB Output is correct
8 Correct 20 ms 2220 KB Output is correct
9 Correct 11 ms 1876 KB Output is correct
10 Correct 11 ms 1876 KB Output is correct
11 Correct 13 ms 1900 KB Output is correct
12 Correct 12 ms 1888 KB Output is correct
13 Correct 16 ms 3152 KB Output is correct
14 Correct 11 ms 1892 KB Output is correct
15 Correct 11 ms 1900 KB Output is correct
16 Correct 18 ms 5036 KB Output is correct
17 Correct 14 ms 2020 KB Output is correct
18 Correct 11 ms 1876 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 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 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct