답안 #643509

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
643509 2022-09-22T08:22:16 Z KindaNameless Martian DNA (BOI18_dna) C++14
100 / 100
33 ms 3504 KB
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<numeric>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<stack>
#include<deque>
#include<cmath>
#include<map>
#include<set>
using namespace std;

#define ll long long
#define ld long double

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int N, K, R; cin >> N >> K >> R;

    vector<int> need(K), cnt(K), D(N+1);
    for(int i = 1; i <= N; ++i){
        cin >> D[i];
    }

    for(int i = 1; i <= R; ++i){
        int B, Q; cin >> B >> Q;
        need[B] = Q;
    }

    int done = 0;
    for(int i = 0; i < K; ++i){
        if(need[i] == 0)done++;
    }

    int l = 1, r, answer = 1e9;
    for(r = 1; r <= N; ++r){
        cnt[D[r]]++;
        if(cnt[D[r]] == need[D[r]])done++;
        while(l < r && cnt[D[l]] > need[D[l]]){
            cnt[D[l++]]--;
        }
        if(done == K){
            answer = min(answer, r - l + 1);
        }
    }

    if(answer > N)cout << "impossible";
    else cout << answer;

    return 0;
}
# 결과 실행 시간 메모리 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 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 320 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 380 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 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 1 ms 320 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 1492 KB Output is correct
2 Correct 11 ms 1492 KB Output is correct
3 Correct 13 ms 1492 KB Output is correct
4 Correct 12 ms 1488 KB Output is correct
5 Correct 18 ms 2516 KB Output is correct
6 Correct 10 ms 1492 KB Output is correct
7 Correct 12 ms 1616 KB Output is correct
8 Correct 20 ms 3500 KB Output is correct
9 Correct 15 ms 2044 KB Output is correct
10 Correct 11 ms 1488 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 324 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 2624 KB Output is correct
2 Correct 23 ms 2392 KB Output is correct
3 Correct 21 ms 2400 KB Output is correct
4 Correct 10 ms 1476 KB Output is correct
5 Correct 28 ms 2764 KB Output is correct
6 Correct 33 ms 3456 KB Output is correct
7 Correct 15 ms 1992 KB Output is correct
8 Correct 19 ms 2080 KB Output is correct
9 Correct 11 ms 1484 KB Output is correct
10 Correct 11 ms 1492 KB Output is correct
11 Correct 13 ms 1492 KB Output is correct
12 Correct 13 ms 1484 KB Output is correct
13 Correct 16 ms 2636 KB Output is correct
14 Correct 10 ms 1488 KB Output is correct
15 Correct 11 ms 1620 KB Output is correct
16 Correct 18 ms 3504 KB Output is correct
17 Correct 14 ms 2000 KB Output is correct
18 Correct 14 ms 1488 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 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 324 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 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 316 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct