Submission #709480

#TimeUsernameProblemLanguageResultExecution timeMemory
709480stevancv Martian DNA (BOI18_dna)C++14
100 / 100
188 ms143160 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define sp ' ' #define en '\n' #define smin(a, b) a = min(a, b) #define smax(a, b) a = max(a, b) using namespace std; const int N = 2e5 + 5; const int inf = 1e9; const int mod = 1e9 + 7; deque<int> dq[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m, k; cin >> n >> m >> k; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<int> b(m); for (int i = 0; i < k; i++) { int x, y; cin >> x >> y; b[x] = y; } set<int> s; int dobri = 0; int ans = 1e6; for (int i = 0; i < n; i++) { if (b[a[i]] == 0) continue; dq[a[i]].push_back(i); if (dq[a[i]].size() > b[a[i]]) { s.erase(dq[a[i]].front()); dq[a[i]].pop_front(); s.insert(dq[a[i]].front()); } else if (dq[a[i]].size() == b[a[i]]) { s.insert(dq[a[i]].front()); dobri += 1; } if (dobri == k) smin(ans, i - *s.begin() + 1); } if (ans == 1e6) cout << "impossible" << en; else cout << ans << en; return 0; }

Compilation message (stderr)

dna.cpp: In function 'int main()':
dna.cpp:33:29: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} [-Wsign-compare]
   33 |         if (dq[a[i]].size() > b[a[i]]) {
dna.cpp:38:34: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} [-Wsign-compare]
   38 |         else if (dq[a[i]].size() == b[a[i]]) {
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...