Submission #482466

#TimeUsernameProblemLanguageResultExecution timeMemory
482466SamAnd Martian DNA (BOI18_dna)C++17
100 / 100
116 ms19524 KiB
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n, k, r; int a[N]; int b[N]; vector<int> v[N]; int j[N]; int main() { scanf("%d%d%d", &n, &k, &r); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); while (r--) { int x, y; scanf("%d%d", &x, &y); b[x] = y; } for (int i = 1; i <= n; ++i) v[a[i]].push_back(i); set<int> s; for (int i = 0; i < k; ++i) { if (!b[i]) continue; if (v[i].size() < b[i]) { printf("impossible\n"); return 0; } j[i] = b[i] - 1; s.insert(v[i][b[i] - 1]); } int ans = (*(--s.end())); for (int i = 2; i <= n; ++i) { if (b[a[i - 1]]) { s.erase(v[a[i - 1]][j[a[i - 1]]]); ++j[a[i - 1]]; if (!(j[a[i - 1]] < v[a[i - 1]].size())) break; s.insert(v[a[i - 1]][j[a[i - 1]]]); } ans = min(ans, (*(--s.end())) - i + 1); } printf("%d\n", ans); return 0; }

Compilation message (stderr)

dna.cpp: In function 'int main()':
dna.cpp:29:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   29 |         if (v[i].size() < b[i])
      |             ~~~~~~~~~~~~^~~~~~
dna.cpp:44:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |             if (!(j[a[i - 1]] < v[a[i - 1]].size()))
      |                   ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
dna.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     scanf("%d%d%d", &n, &k, &r);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
dna.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
dna.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         scanf("%d%d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...