Submission #1111282

#TimeUsernameProblemLanguageResultExecution timeMemory
1111282thangdz2k7 Martian DNA (BOI18_dna)C++17
100 / 100
25 ms2640 KiB
// author : thembululquaUwU // 3.9.2024 #include <bits/stdc++.h> #define pb push_back #define fi first #define se second #define endl '\n' using namespace std; using ll = long long; using ii = pair <int, int>; using vi = vector <int>; const int MaxN = 2e5; const int mod = 1e9 + 7; void maxl(auto &a, auto b) {a = max(a, b);} void minl(auto &a, auto b) {a = min(a, b);} void solve(){ int n, k, r; cin >> n >> k >> r; vector <int> d(n); for (int &f : d) cin >> f; vector <int> needs(k, 0); while (r --){ int B, Q; cin >> B >> Q; needs[B] = Q; } int numok = 0; vector <int> cnt(k, 0); for (int i = 0; i < k; ++ i) numok += (cnt[i] >= needs[i]); auto update = [&](int type, int val) -> void { numok -= (cnt[type] >= needs[type]); cnt[type] += val; numok += (cnt[type] >= needs[type]); }; r = 0; int ans = mod; for (int l = 0; l < n; ++ l){ while (numok < k && r < n) update(d[r ++], 1); if (numok == k) minl(ans, r - l); update(d[l], -1); } if (ans < mod) cout << ans; else cout << "impossible"; } int main(){ if (fopen("dna.inp", "r")){ freopen("dna.inp", "r", stdin); freopen("dna.out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t --) solve(); return 0; }

Compilation message (stderr)

dna.cpp:18:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   18 | void maxl(auto &a, auto b) {a = max(a, b);}
      |           ^~~~
dna.cpp:18:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   18 | void maxl(auto &a, auto b) {a = max(a, b);}
      |                    ^~~~
dna.cpp:19:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   19 | void minl(auto &a, auto b) {a = min(a, b);}
      |           ^~~~
dna.cpp:19:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   19 | void minl(auto &a, auto b) {a = min(a, b);}
      |                    ^~~~
dna.cpp: In function 'int main()':
dna.cpp:54:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |         freopen("dna.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
dna.cpp:55:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |         freopen("dna.out", "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...