답안 #607356

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
607356 2022-07-26T15:51:50 Z kawaii Martian DNA (BOI18_dna) C++14
0 / 100
102 ms 14164 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));
        int cnt = 0;
        // cout << mid << "\n";
        for(int i = 1; i <= n; i++){
            dem[a[i]]++;
            if(i > mid) dem[a[i - mid]]--;
            if(dem[a[i]] >= num[a[i]]){
                if(!flag[a[i]]) flag[a[i]] = 1, ans++;
            }
            if(dem[a[i]] < num[a[i]]){
                if(flag[a[i]]) flag[a[i]] = 0, ans--;
            }
            if(i > mid){
                if(dem[a[i - mid]] < num[a[i - mid]]){
                    if(flag[a[i - mid]]) flag[a[i - mid]] = 0, ans--;
                }
                
                if(dem[a[i - mid]] >= num[a[i - mid]]){
                    if(!flag[a[i - mid]]) flag[a[i - mid]] = 1, ans++;
                }
            }
            answer = max(answer, ans);
            // cout << ans <<" ";
        }
        // cout << "\n";
        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:28:13: warning: unused variable 'cnt' [-Wunused-variable]
   28 |         int cnt = 0;
      |             ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 9044 KB Output is correct
2 Correct 10 ms 9044 KB Output is correct
3 Correct 10 ms 9044 KB Output is correct
4 Correct 10 ms 9044 KB Output is correct
5 Correct 11 ms 9044 KB Output is correct
6 Correct 7 ms 9044 KB Output is correct
7 Incorrect 9 ms 9044 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 9172 KB Output is correct
2 Correct 13 ms 9188 KB Output is correct
3 Incorrect 16 ms 9160 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 11080 KB Output is correct
2 Correct 67 ms 11084 KB Output is correct
3 Correct 56 ms 11124 KB Output is correct
4 Correct 56 ms 11116 KB Output is correct
5 Correct 71 ms 11880 KB Output is correct
6 Correct 46 ms 11084 KB Output is correct
7 Correct 45 ms 11316 KB Output is correct
8 Incorrect 71 ms 11984 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 13076 KB Output is correct
2 Correct 75 ms 12756 KB Output is correct
3 Correct 83 ms 12468 KB Output is correct
4 Correct 55 ms 11088 KB Output is correct
5 Correct 80 ms 13632 KB Output is correct
6 Incorrect 102 ms 14164 KB Output isn't correct
7 Halted 0 ms 0 KB -