Submission #1013781

# Submission time Handle Problem Language Result Execution time Memory
1013781 2024-07-04T05:48:40 Z Muaath_5 Martian DNA (BOI18_dna) C++17
0 / 100
2000 ms 8964 KB
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
using namespace std;

const int N = 2e5+5, INF = 1e9;

int n, k, rr;
int a[N];
int q[N];

int cur[N];

int main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin >> n >> k >> rr;
	for (int i = 1; i <= n; cin >> a[i++]);
	for (int i = 1, b; i <= rr; cin >> b >> q[b], i++);
	int sat = (q[a[1]] && ++cur[a[1]] == q[a[1]]);
	int l = 1, r = 1;
	int sol = INF;
	while (r <= n) {
		cerr << sat << ": " << l << ' ' << r << endl;
		if (sat == rr && l < r) {
			sol = min(sol, r-l+1);
			if (q[a[l]] && cur[a[l]] == q[a[l]]) sat--;
			cur[a[l]]--;
			l++;
		} else {
			r++;
			cur[a[r]]++;
			if (q[a[r]] && cur[a[r]] == q[a[r]]) sat++;
		}
		if (r == n) break;
	}
	while (l <= n && sat == rr) {
		sol = min(sol, r-l+1);
		if (q[a[l]] && cur[a[l]] == q[a[l]]) break;
		cur[a[l]]--;
		l++;
	}
	cout << (sol == INF ? "impossible" : to_string(sol));
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2392 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Incorrect 1 ms 2396 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 41 ms 2568 KB Output is correct
2 Correct 34 ms 2392 KB Output is correct
3 Correct 46 ms 2548 KB Output is correct
4 Correct 45 ms 2396 KB Output is correct
5 Correct 33 ms 2392 KB Output is correct
6 Correct 43 ms 2392 KB Output is correct
7 Correct 2 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Incorrect 1 ms 2392 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1797 ms 6656 KB Output is correct
2 Correct 1951 ms 7824 KB Output is correct
3 Execution timed out 2071 ms 7952 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1833 ms 8736 KB Output is correct
2 Correct 1921 ms 8964 KB Output is correct
3 Correct 1938 ms 8832 KB Output is correct
4 Execution timed out 2073 ms 8016 KB Time limit exceeded
5 Halted 0 ms 0 KB -