Submission #1298572

#TimeUsernameProblemLanguageResultExecution timeMemory
1298572dzhoz0 Martian DNA (BOI18_dna)C++20
0 / 100
90 ms6968 KiB
/* it could have been better :) it will next time ;) */ #include <bits/stdc++.h> using namespace std; #define int long long #define INF 1e18 #define f first #define s second #define pii pair<int, int> #define vi vector<int> const int MOD = 1'000'000'000 + 7; void setIO(string name = "") { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); #ifdef LOCAL freopen("inp.txt", "r", stdin); freopen("out.txt", "w", stdout); #else if (!name.empty()) { freopen((name + ".INP").c_str(), "r", stdin); freopen((name + ".OUT").c_str(), "w", stdout); } #endif } const int MAXN = 2e5; int n, k, q; int a[MAXN + 5]; int req[MAXN + 5]; int cnt[MAXN + 5]; void solve() { cin >> n >> k >> q; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 0; i <= k; i++) req[i] = INF; for(int i = 1; i <= q; i++) { int b; cin >> b; cin >> req[b]; } int l = 1, r = 1; set<int> s; while(r <= n) { cnt[a[r]]++; if(cnt[a[r]] >= req[a[r]]) s.insert(a[r]); if(s.size() == q) break; r++; } if(r == n + 1) { cout << "impossible\n"; return; } int res = INF; while(r <= n) { cnt[a[r]]++; if(cnt[a[r]] >= req[a[r]]) s.insert(a[r]); while(l <= r) { cnt[a[l]]--; if(cnt[a[l]] < req[a[l]]) s.erase(a[l]); if(s.size() == q) l++; else { cnt[a[l]]++; if(cnt[a[l]] >= req[a[l]]) s.insert(a[l]); break; } } res = min(res, r - l + 1); r++; } cout << res << '\n'; } signed main() { setIO(); int t = 1; // cin >> t; while (t--) solve(); }

Compilation message (stderr)

dna.cpp: In function 'void setIO(std::string)':
dna.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen((name + ".INP").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dna.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen((name + ".OUT").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...