Submission #639528

#TimeUsernameProblemLanguageResultExecution timeMemory
639528flappybird Martian DNA (BOI18_dna)C++17
100 / 100
71 ms15884 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx,avx2,fma") using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; #define MAX 201010 #define MAXS 20 #define INF 1000000010 #define bb ' ' #define ln '\n' #define Ln '\n' int arr[MAX]; int ne[MAX]; int num[MAX]; vector<int> v[MAX]; int cnt[MAX]; signed main() { ios::sync_with_stdio(false), cin.tie(0); int N, K, R; cin >> N >> K >> R; int i; for (i = 1; i <= N; i++) cin >> arr[i], v[arr[i]].push_back(i); int a, b; int mx = 1; priority_queue<pii, vector<pii>, greater<pii>> pq; for (i = 1; i <= R; i++) { cin >> a >> b; num[a] = b; if (b > v[a].size()) { cout << "impossible" << ln; return 0; } pq.emplace(v[a][0], a); mx = max(mx, v[a][num[a] - 1]); } int ans = N; while (1) { int t = pq.top().second; ans = min(ans, mx - pq.top().first + 1); pq.pop(); if (cnt[t] + num[t] == v[t].size()) { cout << ans << ln; return 0; } cnt[t]++; mx = max(v[t][cnt[t] + num[t] - 1], mx); pq.emplace(v[t][cnt[t]], t); } cout << ans << ln; }

Compilation message (stderr)

dna.cpp: In function 'int main()':
dna.cpp:33:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |   if (b > v[a].size()) {
      |       ~~^~~~~~~~~~~~~
dna.cpp:45:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |   if (cnt[t] + num[t] == v[t].size()) {
      |       ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...