답안 #607394

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
607394 2022-07-26T16:21:09 Z kawaii Martian DNA (BOI18_dna) C++14
100 / 100
103 ms 12024 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second

int t, n, m, k, b, q, r, a[1000005], num[1000005], dem[1000005], mod = 1e9 + 7;
string s;
mt19937_64 rng;
bool flag[1000005];
int mul(int x, int y){
    if(y == 0) return 1;
    int ans = mul(x, y / 2);
    if(y % 2 == 0) return (ans * ans) % mod;
    else return (((ans * ans) % mod) * x) % mod;
}

void solve(){
    while(r--){
        cin >> b >> q;
        num[b] = q;
    }
    int l = 0; r = n + 1;
    while(r - l > 0){
        int mid = l + r >> 1, ans = 0, answer = 0; 
        memset(dem, 0, sizeof(dem));
        memset(flag, 0, sizeof(flag));
        for(int i = 0; i < k; i++){
            if(!num[i]){
                ans++; flag[i] = 1;
            }
        }
        int cnt = 0;
        // cout << mid << "\n";
        for(int i = 1; i <= n; i++){
            dem[a[i]]++;
            if(dem[a[i]] >= num[a[i]]){
                if(!flag[a[i]]) flag[a[i]] = 1, ans++;
            }
            if(i > mid){
                if(dem[a[i - mid]] == num[a[i - mid]]){
                    if(flag[a[i - mid]]) flag[a[i - mid]] = 0, ans--;
                }
                dem[a[i - mid]]--;
            }
            answer = max(answer, ans);
            // cout << ans <<" ";
        }
        if(answer < k) l = mid + 1;
        else r = mid;
    }
    if(r == n + 1) cout << "impossible";
    else cout << r;
}

signed main(){
    ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr);
    rng.seed((int)main ^ time(0));
    #ifdef Kawaii
        auto starttime = chrono::high_resolution_clock::now();
    #endif

    cin >> n >> k >> r;
    for(int i = 1; i <= n; i++) cin >> a[i];
    solve();

    #ifdef Kawaii
        auto endtime = chrono::high_resolution_clock::now();
        auto duration = chrono::duration_cast<chrono::milliseconds>(endtime - starttime).count(); 
        cout << "\n=====" << "\nUsed: " << duration << " ms\n";
    #endif
}

Compilation message

dna.cpp: In function 'void solve()':
dna.cpp:25:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   25 |         int mid = l + r >> 1, ans = 0, answer = 0;
      |                   ~~^~~
dna.cpp:33:13: warning: unused variable 'cnt' [-Wunused-variable]
   33 |         int cnt = 0;
      |             ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 9044 KB Output is correct
2 Correct 10 ms 9060 KB Output is correct
3 Correct 10 ms 9144 KB Output is correct
4 Correct 7 ms 9044 KB Output is correct
5 Correct 7 ms 9044 KB Output is correct
6 Correct 6 ms 9144 KB Output is correct
7 Correct 11 ms 9064 KB Output is correct
8 Correct 9 ms 9052 KB Output is correct
9 Correct 8 ms 9144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 9172 KB Output is correct
2 Correct 12 ms 9172 KB Output is correct
3 Correct 16 ms 9192 KB Output is correct
4 Correct 15 ms 9180 KB Output is correct
5 Correct 12 ms 9212 KB Output is correct
6 Correct 13 ms 9184 KB Output is correct
7 Correct 8 ms 9044 KB Output is correct
8 Correct 9 ms 9044 KB Output is correct
9 Correct 8 ms 9044 KB Output is correct
10 Correct 7 ms 9044 KB Output is correct
11 Correct 8 ms 9040 KB Output is correct
12 Correct 6 ms 9152 KB Output is correct
13 Correct 8 ms 9044 KB Output is correct
14 Correct 8 ms 9044 KB Output is correct
15 Correct 9 ms 9044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 10632 KB Output is correct
2 Correct 50 ms 10708 KB Output is correct
3 Correct 49 ms 10588 KB Output is correct
4 Correct 46 ms 10692 KB Output is correct
5 Correct 50 ms 10728 KB Output is correct
6 Correct 42 ms 10708 KB Output is correct
7 Correct 37 ms 10708 KB Output is correct
8 Correct 67 ms 10708 KB Output is correct
9 Correct 52 ms 11676 KB Output is correct
10 Correct 45 ms 10976 KB Output is correct
11 Correct 13 ms 9184 KB Output is correct
12 Correct 14 ms 9172 KB Output is correct
13 Correct 11 ms 9172 KB Output is correct
14 Correct 15 ms 9188 KB Output is correct
15 Correct 13 ms 9212 KB Output is correct
16 Correct 13 ms 9172 KB Output is correct
17 Correct 8 ms 9148 KB Output is correct
18 Correct 8 ms 9148 KB Output is correct
19 Correct 7 ms 9040 KB Output is correct
20 Correct 7 ms 9044 KB Output is correct
21 Correct 7 ms 9040 KB Output is correct
22 Correct 6 ms 9044 KB Output is correct
23 Correct 8 ms 9148 KB Output is correct
24 Correct 9 ms 9148 KB Output is correct
25 Correct 9 ms 9044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 11208 KB Output is correct
2 Correct 64 ms 11120 KB Output is correct
3 Correct 70 ms 11072 KB Output is correct
4 Correct 46 ms 10604 KB Output is correct
5 Correct 69 ms 11384 KB Output is correct
6 Correct 103 ms 12008 KB Output is correct
7 Correct 54 ms 11732 KB Output is correct
8 Correct 66 ms 12024 KB Output is correct
9 Correct 41 ms 10968 KB Output is correct
10 Correct 52 ms 11080 KB Output is correct
11 Correct 46 ms 11092 KB Output is correct
12 Correct 46 ms 11052 KB Output is correct
13 Correct 52 ms 11884 KB Output is correct
14 Correct 38 ms 11084 KB Output is correct
15 Correct 42 ms 11272 KB Output is correct
16 Correct 59 ms 11908 KB Output is correct
17 Correct 50 ms 11604 KB Output is correct
18 Correct 47 ms 11108 KB Output is correct
19 Correct 13 ms 9188 KB Output is correct
20 Correct 13 ms 9172 KB Output is correct
21 Correct 15 ms 9192 KB Output is correct
22 Correct 13 ms 9184 KB Output is correct
23 Correct 14 ms 9216 KB Output is correct
24 Correct 14 ms 9172 KB Output is correct
25 Correct 8 ms 9044 KB Output is correct
26 Correct 8 ms 9148 KB Output is correct
27 Correct 8 ms 9044 KB Output is correct
28 Correct 8 ms 9044 KB Output is correct
29 Correct 8 ms 9044 KB Output is correct
30 Correct 7 ms 9044 KB Output is correct
31 Correct 10 ms 9044 KB Output is correct
32 Correct 9 ms 9148 KB Output is correct
33 Correct 9 ms 9092 KB Output is correct