답안 #860968

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
860968 2023-10-14T23:24:36 Z vjudge1 Martian DNA (BOI18_dna) C++17
100 / 100
218 ms 15416 KB
#include <iostream>
#include <vector>
#include <map>
#include <climits>
#define int long long

using namespace std;

signed main() {
    int n, k, r, res = LLONG_MAX, ri = -1;
    bool ok;
    map<int,int> c;
    cin >> n >> k >> r;
    vector<int> a(n), sum(r);
    vector<pair<int,int>> b(r);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < r; i++) {
        cin >> b[i].first >> b[i].second;
        c[b[i].first] = i+1;
    }
    //find start
    while(true) {
        if(ri == n-1) {
            cout << "impossible\n";
            return 0;
        }
        ri++;
        if(c[a[ri]]) {
            sum[c[a[ri]]-1]++;
            ok = true;
            for(int i = 0; i < r; i++) {
                if(sum[i] < b[i].second) {
                    ok = false;
                    break;
                }
            }
            if(ok) break;
        }
    }
    //start
    res = ri+1;
    for(int i = 0; i < n; i++) {
        if(c[a[i]]) {
            sum[c[a[i]]-1]--;
            ok = true;
            while(sum[c[a[i]]-1] < b[c[a[i]]-1].second) {
                if(ri == n-1) {
                    ok = false;
                    break;
                }
                ri++;
                if(c[a[ri]]) sum[c[a[ri]]-1]++;
            }
            if(!ok) break;
        }
        res = min(res, ri-i);
    }
    cout << res << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 1884 KB Output is correct
2 Correct 26 ms 1884 KB Output is correct
3 Correct 32 ms 1884 KB Output is correct
4 Correct 29 ms 1884 KB Output is correct
5 Correct 98 ms 6860 KB Output is correct
6 Correct 27 ms 1884 KB Output is correct
7 Correct 32 ms 1988 KB Output is correct
8 Correct 150 ms 14552 KB Output is correct
9 Correct 67 ms 2488 KB Output is correct
10 Correct 32 ms 1884 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 214 ms 8788 KB Output is correct
2 Correct 176 ms 6992 KB Output is correct
3 Correct 120 ms 6116 KB Output is correct
4 Correct 26 ms 2012 KB Output is correct
5 Correct 147 ms 10092 KB Output is correct
6 Correct 218 ms 15416 KB Output is correct
7 Correct 72 ms 2640 KB Output is correct
8 Correct 109 ms 3392 KB Output is correct
9 Correct 27 ms 1880 KB Output is correct
10 Correct 26 ms 1880 KB Output is correct
11 Correct 32 ms 1884 KB Output is correct
12 Correct 29 ms 1884 KB Output is correct
13 Correct 98 ms 6992 KB Output is correct
14 Correct 26 ms 1884 KB Output is correct
15 Correct 32 ms 1880 KB Output is correct
16 Correct 134 ms 14308 KB Output is correct
17 Correct 67 ms 2384 KB Output is correct
18 Correct 31 ms 1884 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct