답안 #113887

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
113887 2019-05-29T03:22:44 Z Mamnoon_Siam Minerals (JOI19_minerals) C++17
100 / 100
752 ms 5140 KB
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include "minerals.h"
#include <bits/stdc++.h>
using namespace std;

const int maxn = 45000;
int dp[maxn], opt[maxn];

mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }
struct RNG {
	int operator () (int n) {
		return rnd(n);
	}
};

int cnt = 0;

void solve(vector<int> u, vector<int> v, int f) {
	if(u.empty()) return;

	if(u.size() == 1) {
		Answer(u.back(), v.back());
		return;
	}
	int mid, last;
	if(f) {
		mid = u.size() - opt[u.size()];
		for(int i = mid; i < v.size(); i++) {
			last = Query(v[i]); cnt++;
		}
	} else {
		mid = opt[u.size()];
		for(int i = 0; i < mid; i++) {
			last = Query(v[i]); cnt++;
		}
	}
	vector<int> lu, lv(v.begin(), v.begin() + mid), ru, rv(v.begin() + mid, v.end());
	for(int i = 0; i < u.size(); i++) {
		if(lu.size() == lv.size()) {
			ru.emplace_back(u[i]);
		} else if(ru.size() == rv.size()) {
			lu.emplace_back(u[i]);
		} else {
			int rep = Query(u[i]); cnt++;
			if(rep == last) {
				lu.emplace_back(u[i]);
			} else {
				ru.emplace_back(u[i]);
			}
			last = rep;
		}
	}
	solve(lu, lv, 1);
	solve(ru, rv, 0);
}

void split(vector<int> v) {
	vector<int> l, r;
	int last = -1;
	for(int i = 0; i < v.size(); i++) {
		if(r.size() == v.size() / 2) {
			l.emplace_back(v[i]);
			continue;
		}
		int rep = Query(v[i]); cnt++;
		if(rep == last) {
			l.emplace_back(v[i]);
		} else {
			r.emplace_back(v[i]);
		} last = rep;
	}
	solve(l, r, 1);
}

void Solve(int N) {
	dp[1] = 0;
	for(int i = 2; i <= N; i++) {
		int mn = INT_MAX, tmp, arg, cmp = (i - 1) / 2 + 1;
		for(int j = 1; j < i; j++) {
			tmp = dp[j] + dp[i - j] + (j < cmp ? j : i - j);
			if(tmp < mn) {
				mn = tmp;
				arg = j;
			}
		}
		dp[i] = mn + i;
		opt[i] = arg;
	}
	vector<int> v(2 * N);
	iota(v.begin(), v.end(), 1);
	split(v);
	assert(cnt <= 999975);
}

Compilation message

minerals.cpp: In function 'void solve(std::vector<int>, std::vector<int>, int)':
minerals.cpp:30:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = mid; i < v.size(); i++) {
                    ~~^~~~~~~~~~
minerals.cpp:40:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < u.size(); i++) {
                 ~~^~~~~~~~~~
minerals.cpp: In function 'void split(std::vector<int>)':
minerals.cpp:62:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < v.size(); i++) {
                 ~~^~~~~~~~~~
minerals.cpp: In function 'void solve(std::vector<int>, std::vector<int>, int)':
minerals.cpp:47:4: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
    if(rep == last) {
    ^~
minerals.cpp: In function 'void Solve(int)':
minerals.cpp:89:10: warning: 'arg' may be used uninitialized in this function [-Wmaybe-uninitialized]
   opt[i] = arg;
   ~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 12 ms 640 KB Output is correct
4 Correct 41 ms 1144 KB Output is correct
5 Correct 106 ms 1828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 12 ms 640 KB Output is correct
8 Correct 41 ms 1144 KB Output is correct
9 Correct 106 ms 1828 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 51 ms 1404 KB Output is correct
12 Correct 104 ms 1912 KB Output is correct
13 Correct 102 ms 1948 KB Output is correct
14 Correct 101 ms 1864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 12 ms 640 KB Output is correct
8 Correct 41 ms 1144 KB Output is correct
9 Correct 106 ms 1828 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 51 ms 1404 KB Output is correct
12 Correct 104 ms 1912 KB Output is correct
13 Correct 102 ms 1948 KB Output is correct
14 Correct 101 ms 1864 KB Output is correct
15 Correct 589 ms 4580 KB Output is correct
16 Correct 600 ms 4624 KB Output is correct
17 Correct 582 ms 4320 KB Output is correct
18 Correct 582 ms 4112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 12 ms 640 KB Output is correct
8 Correct 41 ms 1144 KB Output is correct
9 Correct 106 ms 1828 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 51 ms 1404 KB Output is correct
12 Correct 104 ms 1912 KB Output is correct
13 Correct 102 ms 1948 KB Output is correct
14 Correct 101 ms 1864 KB Output is correct
15 Correct 589 ms 4580 KB Output is correct
16 Correct 600 ms 4624 KB Output is correct
17 Correct 582 ms 4320 KB Output is correct
18 Correct 582 ms 4112 KB Output is correct
19 Correct 631 ms 4720 KB Output is correct
20 Correct 618 ms 4784 KB Output is correct
21 Correct 618 ms 4468 KB Output is correct
22 Correct 602 ms 4212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 12 ms 640 KB Output is correct
8 Correct 41 ms 1144 KB Output is correct
9 Correct 106 ms 1828 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 51 ms 1404 KB Output is correct
12 Correct 104 ms 1912 KB Output is correct
13 Correct 102 ms 1948 KB Output is correct
14 Correct 101 ms 1864 KB Output is correct
15 Correct 589 ms 4580 KB Output is correct
16 Correct 600 ms 4624 KB Output is correct
17 Correct 582 ms 4320 KB Output is correct
18 Correct 582 ms 4112 KB Output is correct
19 Correct 631 ms 4720 KB Output is correct
20 Correct 618 ms 4784 KB Output is correct
21 Correct 618 ms 4468 KB Output is correct
22 Correct 602 ms 4212 KB Output is correct
23 Correct 705 ms 4888 KB Output is correct
24 Correct 647 ms 4696 KB Output is correct
25 Correct 661 ms 4748 KB Output is correct
26 Correct 668 ms 4340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 12 ms 640 KB Output is correct
8 Correct 41 ms 1144 KB Output is correct
9 Correct 106 ms 1828 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 51 ms 1404 KB Output is correct
12 Correct 104 ms 1912 KB Output is correct
13 Correct 102 ms 1948 KB Output is correct
14 Correct 101 ms 1864 KB Output is correct
15 Correct 589 ms 4580 KB Output is correct
16 Correct 600 ms 4624 KB Output is correct
17 Correct 582 ms 4320 KB Output is correct
18 Correct 582 ms 4112 KB Output is correct
19 Correct 631 ms 4720 KB Output is correct
20 Correct 618 ms 4784 KB Output is correct
21 Correct 618 ms 4468 KB Output is correct
22 Correct 602 ms 4212 KB Output is correct
23 Correct 705 ms 4888 KB Output is correct
24 Correct 647 ms 4696 KB Output is correct
25 Correct 661 ms 4748 KB Output is correct
26 Correct 668 ms 4340 KB Output is correct
27 Correct 680 ms 4948 KB Output is correct
28 Correct 695 ms 4964 KB Output is correct
29 Correct 668 ms 4640 KB Output is correct
30 Correct 663 ms 4468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 12 ms 640 KB Output is correct
8 Correct 41 ms 1144 KB Output is correct
9 Correct 106 ms 1828 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 51 ms 1404 KB Output is correct
12 Correct 104 ms 1912 KB Output is correct
13 Correct 102 ms 1948 KB Output is correct
14 Correct 101 ms 1864 KB Output is correct
15 Correct 589 ms 4580 KB Output is correct
16 Correct 600 ms 4624 KB Output is correct
17 Correct 582 ms 4320 KB Output is correct
18 Correct 582 ms 4112 KB Output is correct
19 Correct 631 ms 4720 KB Output is correct
20 Correct 618 ms 4784 KB Output is correct
21 Correct 618 ms 4468 KB Output is correct
22 Correct 602 ms 4212 KB Output is correct
23 Correct 705 ms 4888 KB Output is correct
24 Correct 647 ms 4696 KB Output is correct
25 Correct 661 ms 4748 KB Output is correct
26 Correct 668 ms 4340 KB Output is correct
27 Correct 680 ms 4948 KB Output is correct
28 Correct 695 ms 4964 KB Output is correct
29 Correct 668 ms 4640 KB Output is correct
30 Correct 663 ms 4468 KB Output is correct
31 Correct 720 ms 5140 KB Output is correct
32 Correct 703 ms 4864 KB Output is correct
33 Correct 698 ms 4680 KB Output is correct
34 Correct 709 ms 4600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 12 ms 640 KB Output is correct
8 Correct 41 ms 1144 KB Output is correct
9 Correct 106 ms 1828 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 51 ms 1404 KB Output is correct
12 Correct 104 ms 1912 KB Output is correct
13 Correct 102 ms 1948 KB Output is correct
14 Correct 101 ms 1864 KB Output is correct
15 Correct 589 ms 4580 KB Output is correct
16 Correct 600 ms 4624 KB Output is correct
17 Correct 582 ms 4320 KB Output is correct
18 Correct 582 ms 4112 KB Output is correct
19 Correct 631 ms 4720 KB Output is correct
20 Correct 618 ms 4784 KB Output is correct
21 Correct 618 ms 4468 KB Output is correct
22 Correct 602 ms 4212 KB Output is correct
23 Correct 705 ms 4888 KB Output is correct
24 Correct 647 ms 4696 KB Output is correct
25 Correct 661 ms 4748 KB Output is correct
26 Correct 668 ms 4340 KB Output is correct
27 Correct 680 ms 4948 KB Output is correct
28 Correct 695 ms 4964 KB Output is correct
29 Correct 668 ms 4640 KB Output is correct
30 Correct 663 ms 4468 KB Output is correct
31 Correct 720 ms 5140 KB Output is correct
32 Correct 703 ms 4864 KB Output is correct
33 Correct 698 ms 4680 KB Output is correct
34 Correct 709 ms 4600 KB Output is correct
35 Correct 752 ms 5004 KB Output is correct
36 Correct 741 ms 5108 KB Output is correct
37 Correct 747 ms 4888 KB Output is correct
38 Correct 729 ms 4468 KB Output is correct