Submission #519708

#TimeUsernameProblemLanguageResultExecution timeMemory
519708Ierus Martian DNA (BOI18_dna)C++17
100 / 100
32 ms3144 KiB
#include<bits/stdc++.h> using namespace std; #pragma GCC optimize ("unroll-loops,Ofast,O3") #pragma GCC target("avx,avx2,fma") #define F first #define S second #define sz(x) (int)x.size() #define pb push_back #define eb emplace_back #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define NFS ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ; #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout) typedef long long ll; //random_device(rd); //mt19937 rng(rd()); //const long long FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); //template<class T> T randomize(T mod){ // return (uniform_int_distribution<T>(0, mod))(rng); //} const int E = 1e6+777; const long long inf = 1e18+777; const int N = 2e5+777; const int MOD = 1e9+7; const bool I = 0; int n, k, r, a[N], need[N], have[N], sum; int main(){const auto solve=[&]() -> void{ cin >> n >> k >> r; for(int i = 1; i <= n; ++i){ cin >> a[i]; } for(int i = 0; i < r; ++i){ int id, val; cin >> id >> val; need[id] = val; } int R = 0, res = INT_MAX; for(int L = 1; L <= n; ++L){ while(R < L - 1){ if(need[a[R]] == have[a[R]]){ --sum; } --have[R]; ++R; } while(sum < r && R + 1 <= n){ ++R; ++have[a[R]]; if(need[a[R]] == have[a[R]]){ ++sum; } // cerr << "R: " << R << " have["<<a[R]<<"]: " << have[a[R]] << " sum: " << sum << '\n'; } if(sum == r) res = min(res, R - L + 1); // cerr << "L: " << L << " R: " << R << " sum: " << sum << '\n'; if(need[a[L]] == have[a[L]]){ --sum; } --have[a[L]]; } if(res == INT_MAX) cout << "impossible"; else cout << res; };NFS;int T=1;if(I)cin>>T;while(T--)solve();}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...