답안 #386221

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
386221 2021-04-06T06:41:30 Z maximath_1 Martian DNA (BOI18_dna) C++11
100 / 100
151 ms 5356 KB
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <numeric>
#include <iostream>
#include <queue>
#include <assert.h>
#include <map>
#include <set>
#include <limits.h>
#include <random>
#include <chrono>
using namespace std;
 
#define ll long long
#define ld long double
const int MX = 200005;
const int BLOCK = 105;
const ll mod = 1e9 + 7;
const ll inv2 = (mod + 1) / 2;
const int dxh[] = {1, 1, -1, -1, 2, 2, -2, -2};
const int dyh[] = {2, -2, 2, -2, 1, -1, 1, -1}; // horse
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1}; // adj
const int dxd[] = {1, 1, 1, 0, -1, -1, -1, 0};
const int dyd[] = {1, 0, -1, -1, -1, 0, 1, 1}; // diag

int n, k, r, v[MX];
int st[MX * 4];

void upd(int nd, int cl, int cr, int ps, int val){
	if(ps < cl || cr < ps) return;
	if(cl == cr) return void(st[nd] += val);

	upd(nd * 2, cl, (cl + cr) / 2, ps, val);
	upd(nd * 2 + 1, (cl + cr) / 2 + 1, cr, ps, val);
	st[nd] = max(st[nd * 2], st[nd * 2 + 1]);
}

int main(){
	cin.tie(0) -> sync_with_stdio(0);

	cin >> n >> k >> r;
	for(int i = 0; i < n; i ++)
		cin >> v[i];

	for(int a, c, i = 0; i < r; i ++){
		cin >> a >> c;
		upd(1, 0, k - 1, a, c);
	}

	int ans = MX + MX + MX;
	for(int i = 0, j = -1; i < n; i ++){
		for(; j < n && st[1] > 0; upd(1, 0, k - 1, v[++ j], -1));
		if(j >= n) break;

		ans = min(ans, j - i + 1);
		upd(1, 0, k - 1, v[i], 1);
	}

	if(ans > n) cout << "impossible\n";
	else cout << ans << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 412 KB Output is correct
4 Correct 3 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 1516 KB Output is correct
2 Correct 23 ms 1516 KB Output is correct
3 Correct 32 ms 1536 KB Output is correct
4 Correct 32 ms 1516 KB Output is correct
5 Correct 101 ms 3308 KB Output is correct
6 Correct 23 ms 1516 KB Output is correct
7 Correct 33 ms 1772 KB Output is correct
8 Correct 109 ms 4460 KB Output is correct
9 Correct 78 ms 2156 KB Output is correct
10 Correct 29 ms 1516 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 ms 364 KB Output is correct
14 Correct 3 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 131 ms 4076 KB Output is correct
2 Correct 122 ms 3300 KB Output is correct
3 Correct 107 ms 2924 KB Output is correct
4 Correct 20 ms 1516 KB Output is correct
5 Correct 108 ms 4332 KB Output is correct
6 Correct 151 ms 5356 KB Output is correct
7 Correct 59 ms 2156 KB Output is correct
8 Correct 85 ms 2540 KB Output is correct
9 Correct 27 ms 1576 KB Output is correct
10 Correct 21 ms 1532 KB Output is correct
11 Correct 38 ms 1516 KB Output is correct
12 Correct 28 ms 1516 KB Output is correct
13 Correct 104 ms 3308 KB Output is correct
14 Correct 23 ms 1516 KB Output is correct
15 Correct 32 ms 1644 KB Output is correct
16 Correct 109 ms 4588 KB Output is correct
17 Correct 77 ms 2156 KB Output is correct
18 Correct 31 ms 1516 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 3 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 2 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 388 KB Output is correct
27 Correct 2 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct