답안 #941709

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
941709 2024-03-09T10:28:38 Z phoenix0423 Martian DNA (BOI18_dna) C++17
100 / 100
42 ms 4688 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#pragma GCC optimize("Ofast")
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define lowbit(x) x&-x
const int maxn = 2e5 + 5;
int req[maxn];

signed main(void){
    fastio;
    int n, k, r;
    cin>>n>>k>>r;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin>>a[i];
    for(int i = 0; i < r; i++){
        int b, t;
        cin>>b>>t;
        req[b] = t;
    }
    int L = 0, R = n + 1;
    while(L + 1 < R){
        int m = (L + R) / 2;
        int ok = k - r;
        vector<int> cur(k);
        for(int i = 0; i < m; i++){
            cur[a[i]] ++;
            if(cur[a[i]] == req[a[i]]) ok++;
        }
        if(ok == k){
            R = m;
            continue;
        }
        int pass = 0;
        for(int i = m; i < n; i++){
            cur[a[i]] ++;
            if(cur[a[i]] == req[a[i]]) ok++;
            cur[a[i - m]] --;
            if(cur[a[i - m]] == req[a[i - m]] - 1) ok--;
            if(ok == k) pass = 1;
        }
        if(pass) R = m;
        else L = m;
    }
    if(R == n + 1) cout<<"impossible\n";
    else cout<<R<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 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 348 KB Output is correct
4 Correct 1 ms 484 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 1880 KB Output is correct
2 Correct 19 ms 1628 KB Output is correct
3 Correct 14 ms 1628 KB Output is correct
4 Correct 15 ms 1628 KB Output is correct
5 Correct 25 ms 2652 KB Output is correct
6 Correct 14 ms 1636 KB Output is correct
7 Correct 15 ms 1632 KB Output is correct
8 Correct 29 ms 3156 KB Output is correct
9 Correct 21 ms 2020 KB Output is correct
10 Correct 16 ms 1628 KB Output is correct
11 Correct 1 ms 352 KB Output is correct
12 Correct 1 ms 480 KB Output is correct
13 Correct 1 ms 472 KB Output is correct
14 Correct 1 ms 352 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 344 KB Output is correct
19 Correct 0 ms 352 KB Output is correct
20 Correct 0 ms 480 KB Output is correct
21 Correct 1 ms 360 KB Output is correct
22 Correct 2 ms 360 KB Output is correct
23 Correct 0 ms 472 KB Output is correct
24 Correct 0 ms 352 KB Output is correct
25 Correct 1 ms 360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 3628 KB Output is correct
2 Correct 41 ms 3196 KB Output is correct
3 Correct 39 ms 2940 KB Output is correct
4 Correct 13 ms 1500 KB Output is correct
5 Correct 31 ms 4184 KB Output is correct
6 Correct 42 ms 4688 KB Output is correct
7 Correct 20 ms 2136 KB Output is correct
8 Correct 29 ms 2520 KB Output is correct
9 Correct 14 ms 1624 KB Output is correct
10 Correct 19 ms 1628 KB Output is correct
11 Correct 19 ms 1628 KB Output is correct
12 Correct 13 ms 1508 KB Output is correct
13 Correct 31 ms 2652 KB Output is correct
14 Correct 12 ms 1624 KB Output is correct
15 Correct 13 ms 1628 KB Output is correct
16 Correct 32 ms 3320 KB Output is correct
17 Correct 19 ms 2136 KB Output is correct
18 Correct 14 ms 1628 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct