Submission #916635

#TimeUsernameProblemLanguageResultExecution timeMemory
916635penguin133 Martian DNA (BOI18_dna)C++17
100 / 100
37 ms6996 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pi pair<int, int> #define pii pair<int, pi> #define fi first #define se second #ifdef _WIN32 #define getchar_unlocked _getchar_nolock #endif mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); int n, m, k, A[200005], req[200005], cur[200005]; void solve(){ cin >> n >> m >> k; for(int i = 1; i <= n; i++)cin >> A[i]; int cnt = 0; for(int i = 1; i <= k; i++){ int a, b; cin >> a >> b; req[a] = max(req[a], b); } int ans = 1e18, l = 1; for(int i = 0; i < m; i++)if(!req[i])cnt++; for(int i = 1; i <= n; i++){ cur[A[i]]++; if(cur[A[i]] == req[A[i]])cnt++; while(cnt == m){ ans = min(ans, i - l + 1); cur[A[l]]--; if(cur[A[l]] == req[A[l]] - 1)cnt--; l++; } } if(ans == 1e18)cout << "impossible"; else cout << ans; cout << '\n'; } main(){ ios::sync_with_stdio(0);cin.tie(0); int tc = 1; //cin >> tc; for(int tc1=1;tc1<=tc;tc1++){ // cout << "Case #" << tc1 << ": "; solve(); } }

Compilation message (stderr)

dna.cpp:41:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   41 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...