Submission #957400

#TimeUsernameProblemLanguageResultExecution timeMemory
957400vjudge1 Martian DNA (BOI18_dna)C++17
40 / 100
796 ms1048576 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define fi first #define se second #define pii pair<int, int> #define pll pair<ll, ll> const ll N = 200069; const ll mod = 1e9 + 7; int tc; ll n, k, r; int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); ll i, j; cin >> n >> k >> r; ll pref[n+1][k+1]; memset(pref, 0, sizeof(pref)); for(i = 1; i <= n; i++) { for(j = 0; j < k; j++) pref[i][j] = pref[i-1][j]; ll x; cin >> x; ++pref[i][x]; } ll need[k+1]; memset(need, 0, sizeof(need)); bool bisa = 1; ll sm = 0; for(i = 1; i <= r; i++) { ll x, y; cin >> x >> y; need[x] = y; sm += y; if(need[x] > pref[n][x]) { bisa = 0; } } if(!bisa) { cout << "impossible" << '\n'; return 0; } ll ans = n; for(i = sm; i <= n; i++) { ll cn = 0; for(j = 0; j < k; j++) cn += pref[i][j] >= need[j]; if(cn == k) { ll l = 0, r = i; while(l <= r) { ll mid = (l + r)/2; ll res = 0; for(j = 0; j < k; j++) res += pref[i][j] - pref[mid][j] >= need[j]; if(res == k) { ans = min(ans, i - mid); l = mid + 1; } else r = mid - 1; } } } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...