답안 #263590

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
263590 2020-08-13T19:52:00 Z keko37 Minerals (JOI19_minerals) C++14
100 / 100
75 ms 4252 KB
#include<bits/stdc++.h>
#include "minerals.h"

using namespace std;

typedef vector <int> vi;

const int MAXN = 45000;

int n, prosli = 0;
int dp[MAXN], opt[MAXN];

int calc (int len) {
    if (dp[len] != -1) return dp[len];
    if (len == 1) return dp[len] = 0;
    int res = 1e9;
    int x = (double) len / 2.618;
    for (int j = 0; j <= 1; j++) {
        int i = x + j;
        if (i < 1 || i >= len) continue;
        int tmp = min(i, len - i) + len - 1 + calc(i) + calc(len - i);
        if (tmp < res) {
            res = tmp;
            opt[len] = i;
        }
    }
    return dp[len] = res;
}

bool pitaj (int x) {
	int novi = Query(x);
	bool res = (prosli != novi);
	prosli = novi;
	return res;
}

void calc (vi a, vi b, bool flg) {
	int siz = a.size();
	if (siz == 1) {
		Answer(a[0], b[0]);
		return;
	}
	int x = opt[siz];
	vi a1, b1, a2, b2;
	for (int i = 0; i < siz; i++) {
		if (i < x) {
			pitaj(a[i]);
			a1.push_back(a[i]);
		} else {
			a2.push_back(a[i]);
		}
	}
	for (int i = 0; i < siz; i++) {
		if (b1.size() == a1.size()) {b2.push_back(b[i]); continue;}
		if (b2.size() == a2.size()) {b1.push_back(b[i]); continue;}
		if (pitaj(b[i]) ^ flg) b2.push_back(b[i]); else b1.push_back(b[i]);
	}
	calc(a1, b1, !flg);
	calc(a2, b2, flg);
}

void init () {
	vi a, b;
	for (int i = 1; i <= 2 * n; i++) {
		if (pitaj(i)) a.push_back(i); else b.push_back(i);
	}
	calc(a, b, 1);
}

void Solve (int N) {
	n = N;
	memset(dp, -1, sizeof dp);
	calc(n);
	init();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 640 KB Output is correct
2 Correct 3 ms 640 KB Output is correct
3 Correct 6 ms 896 KB Output is correct
4 Correct 12 ms 1156 KB Output is correct
5 Correct 23 ms 1780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
7 Correct 6 ms 896 KB Output is correct
8 Correct 12 ms 1156 KB Output is correct
9 Correct 23 ms 1780 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 15 ms 1356 KB Output is correct
12 Correct 24 ms 1804 KB Output is correct
13 Correct 18 ms 1800 KB Output is correct
14 Correct 24 ms 1804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
7 Correct 6 ms 896 KB Output is correct
8 Correct 12 ms 1156 KB Output is correct
9 Correct 23 ms 1780 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 15 ms 1356 KB Output is correct
12 Correct 24 ms 1804 KB Output is correct
13 Correct 18 ms 1800 KB Output is correct
14 Correct 24 ms 1804 KB Output is correct
15 Correct 66 ms 3800 KB Output is correct
16 Correct 69 ms 3820 KB Output is correct
17 Correct 55 ms 3752 KB Output is correct
18 Correct 57 ms 3608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
7 Correct 6 ms 896 KB Output is correct
8 Correct 12 ms 1156 KB Output is correct
9 Correct 23 ms 1780 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 15 ms 1356 KB Output is correct
12 Correct 24 ms 1804 KB Output is correct
13 Correct 18 ms 1800 KB Output is correct
14 Correct 24 ms 1804 KB Output is correct
15 Correct 66 ms 3800 KB Output is correct
16 Correct 69 ms 3820 KB Output is correct
17 Correct 55 ms 3752 KB Output is correct
18 Correct 57 ms 3608 KB Output is correct
19 Correct 62 ms 3800 KB Output is correct
20 Correct 65 ms 3940 KB Output is correct
21 Correct 59 ms 3856 KB Output is correct
22 Correct 56 ms 3672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
7 Correct 6 ms 896 KB Output is correct
8 Correct 12 ms 1156 KB Output is correct
9 Correct 23 ms 1780 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 15 ms 1356 KB Output is correct
12 Correct 24 ms 1804 KB Output is correct
13 Correct 18 ms 1800 KB Output is correct
14 Correct 24 ms 1804 KB Output is correct
15 Correct 66 ms 3800 KB Output is correct
16 Correct 69 ms 3820 KB Output is correct
17 Correct 55 ms 3752 KB Output is correct
18 Correct 57 ms 3608 KB Output is correct
19 Correct 62 ms 3800 KB Output is correct
20 Correct 65 ms 3940 KB Output is correct
21 Correct 59 ms 3856 KB Output is correct
22 Correct 56 ms 3672 KB Output is correct
23 Correct 75 ms 3968 KB Output is correct
24 Correct 71 ms 3868 KB Output is correct
25 Correct 55 ms 3912 KB Output is correct
26 Correct 55 ms 3712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
7 Correct 6 ms 896 KB Output is correct
8 Correct 12 ms 1156 KB Output is correct
9 Correct 23 ms 1780 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 15 ms 1356 KB Output is correct
12 Correct 24 ms 1804 KB Output is correct
13 Correct 18 ms 1800 KB Output is correct
14 Correct 24 ms 1804 KB Output is correct
15 Correct 66 ms 3800 KB Output is correct
16 Correct 69 ms 3820 KB Output is correct
17 Correct 55 ms 3752 KB Output is correct
18 Correct 57 ms 3608 KB Output is correct
19 Correct 62 ms 3800 KB Output is correct
20 Correct 65 ms 3940 KB Output is correct
21 Correct 59 ms 3856 KB Output is correct
22 Correct 56 ms 3672 KB Output is correct
23 Correct 75 ms 3968 KB Output is correct
24 Correct 71 ms 3868 KB Output is correct
25 Correct 55 ms 3912 KB Output is correct
26 Correct 55 ms 3712 KB Output is correct
27 Correct 67 ms 3972 KB Output is correct
28 Correct 64 ms 3952 KB Output is correct
29 Correct 50 ms 4008 KB Output is correct
30 Correct 59 ms 3848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
7 Correct 6 ms 896 KB Output is correct
8 Correct 12 ms 1156 KB Output is correct
9 Correct 23 ms 1780 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 15 ms 1356 KB Output is correct
12 Correct 24 ms 1804 KB Output is correct
13 Correct 18 ms 1800 KB Output is correct
14 Correct 24 ms 1804 KB Output is correct
15 Correct 66 ms 3800 KB Output is correct
16 Correct 69 ms 3820 KB Output is correct
17 Correct 55 ms 3752 KB Output is correct
18 Correct 57 ms 3608 KB Output is correct
19 Correct 62 ms 3800 KB Output is correct
20 Correct 65 ms 3940 KB Output is correct
21 Correct 59 ms 3856 KB Output is correct
22 Correct 56 ms 3672 KB Output is correct
23 Correct 75 ms 3968 KB Output is correct
24 Correct 71 ms 3868 KB Output is correct
25 Correct 55 ms 3912 KB Output is correct
26 Correct 55 ms 3712 KB Output is correct
27 Correct 67 ms 3972 KB Output is correct
28 Correct 64 ms 3952 KB Output is correct
29 Correct 50 ms 4008 KB Output is correct
30 Correct 59 ms 3848 KB Output is correct
31 Correct 67 ms 4028 KB Output is correct
32 Correct 71 ms 4040 KB Output is correct
33 Correct 54 ms 4028 KB Output is correct
34 Correct 58 ms 3900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
7 Correct 6 ms 896 KB Output is correct
8 Correct 12 ms 1156 KB Output is correct
9 Correct 23 ms 1780 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 15 ms 1356 KB Output is correct
12 Correct 24 ms 1804 KB Output is correct
13 Correct 18 ms 1800 KB Output is correct
14 Correct 24 ms 1804 KB Output is correct
15 Correct 66 ms 3800 KB Output is correct
16 Correct 69 ms 3820 KB Output is correct
17 Correct 55 ms 3752 KB Output is correct
18 Correct 57 ms 3608 KB Output is correct
19 Correct 62 ms 3800 KB Output is correct
20 Correct 65 ms 3940 KB Output is correct
21 Correct 59 ms 3856 KB Output is correct
22 Correct 56 ms 3672 KB Output is correct
23 Correct 75 ms 3968 KB Output is correct
24 Correct 71 ms 3868 KB Output is correct
25 Correct 55 ms 3912 KB Output is correct
26 Correct 55 ms 3712 KB Output is correct
27 Correct 67 ms 3972 KB Output is correct
28 Correct 64 ms 3952 KB Output is correct
29 Correct 50 ms 4008 KB Output is correct
30 Correct 59 ms 3848 KB Output is correct
31 Correct 67 ms 4028 KB Output is correct
32 Correct 71 ms 4040 KB Output is correct
33 Correct 54 ms 4028 KB Output is correct
34 Correct 58 ms 3900 KB Output is correct
35 Correct 67 ms 4240 KB Output is correct
36 Correct 67 ms 4252 KB Output is correct
37 Correct 71 ms 4192 KB Output is correct
38 Correct 70 ms 3980 KB Output is correct