Submission #645161

#TimeUsernameProblemLanguageResultExecution timeMemory
645161mychecksedad Martian DNA (BOI18_dna)C++17
68 / 100
2078 ms20320 KiB
/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define setp() cout << setprecision(15)
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " is " << x << '\n';
const int N = 1e6+100, M = 1e5+10, F = 2147483646, K = 20;



int n, k, s, a[N], dp[N][11], arr[N];
map<int, int> m;
void solve(){
    cin >> n >> k >> s;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    for(int i = 1; i <= s; ++i){
        int c, x; cin >> c >> x;
        arr[i] = x;
        m[c] = i;
    }
    for(int i = 0; i <= n; ++i) for(int j = 0; j <= s; ++j) dp[i][j] = 0;
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= s; ++j) dp[i][j] = dp[i - 1][j];
        dp[i][m[a[i]]]++;
    }
    int best = MOD;
    for(int i = 1; i <= n; ++i){
        int l = 1, r = i, ans = -1;
        while(l <= r){
            int mid = (l + r) >> 1;
            bool ok = 1;
            for(int j = 1; j <= s; ++j) if(dp[i][j] - dp[mid - 1][j] < arr[j]) ok = 0;
            if(ok){
                ans = mid;
                l = mid + 1;
            }else r = mid - 1;
        }
        if(ans > -1) best = min(best, i - ans + 1);
    }
    if(best == MOD) cout << "impossible";
    else cout << best; 
}





int main(){
    cin.tie(0); ios::sync_with_stdio(0);
    int T = 1, aa;
    // cin >> T;aa=T;
    while(T--){
        // cout << "Case #" << aa-T << ": ";
        solve();
        cout << '\n';
    }
    return 0;
 
}

Compilation message (stderr)

dna.cpp: In function 'int main()':
dna.cpp:56:16: warning: unused variable 'aa' [-Wunused-variable]
   56 |     int T = 1, aa;
      |                ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...