Submission #639527

# Submission time Handle Problem Language Result Execution time Memory
639527 2022-09-10T12:37:16 Z flappybird Martian DNA (BOI18_dna) C++17
0 / 100
51 ms 11564 KB
#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] + 1 + 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

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:27: 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] + 1 + num[t] == v[t].size()) {
      |       ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Incorrect 2 ms 4948 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5056 KB Output is correct
2 Correct 3 ms 5060 KB Output is correct
3 Correct 4 ms 5076 KB Output is correct
4 Runtime error 12 ms 10332 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 7592 KB Output is correct
2 Correct 28 ms 7292 KB Output is correct
3 Correct 21 ms 7180 KB Output is correct
4 Correct 16 ms 7452 KB Output is correct
5 Incorrect 31 ms 9596 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 50 ms 11564 KB Output is correct
2 Incorrect 51 ms 10504 KB Output isn't correct
3 Halted 0 ms 0 KB -