Submission #250478

# Submission time Handle Problem Language Result Execution time Memory
250478 2020-07-18T07:12:17 Z lyc Minerals (JOI19_minerals) C++14
70 / 100
53 ms 3060 KB
#include "minerals.h"
#include <bits/stdc++.h>

#define TRACE(x) std::cerr << #x << " :: " << x << std::endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)

const int mxN = 43005;

int inside[2*mxN];
int curVal, curAns;

int Add(int i) {
	if (!inside[i]) {
		inside[i] = true;
		curVal = Query(i);
	}
	return curVal;
}

int Del(int i) {
	if (inside[i]) {
		inside[i] = false;
		curVal = Query(i);
	}
	return curVal;
}

void Ans(int a, int b) { Answer(a,b); ++curAns; }

void rec(std::vector<int>& a, std::vector<int>& b) {
	//~ for (int x : a) std::cout << x << ' ';
	//~ std::cout << "| ";
	//~ for (int x : b) std::cout << x << ' ';
	//~ std::cout << std::endl;
	
	if (SZ(a) == 1) { Ans(a[0],b[0]); return; }
	
	int m = (SZ(a)-1)/2;
	std::vector<int> ax, ay, bx, by;
	FOR(i,0,m){
		ax.push_back(a[i]);
		Add(a[i]);
	}
	FOR(i,m+1,SZ(a)-1){
		ay.push_back(a[i]);
		Del(a[i]);
	}
	
	for (int& e : b) {
		int r = curVal;
		if ((inside[e] ? Del(e) : Add(e)) == r) bx.push_back(e);
		else by.push_back(e);
	}
	
	rec(ax,bx);
	rec(ay,by);
}

void Solve(int N) {
	std::vector<int> a, b;
	
	int r = 0;
	FOR(i,1,2*N){
		int s = Add(i);
		if (s > r) a.push_back(i), r = s;
		else b.push_back(i), Del(i);
	}
	
	rec(a,b);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 9 ms 768 KB Output is correct
5 Correct 18 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 9 ms 768 KB Output is correct
9 Correct 18 ms 1280 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 14 ms 1024 KB Output is correct
12 Correct 21 ms 1280 KB Output is correct
13 Correct 16 ms 1280 KB Output is correct
14 Correct 16 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 9 ms 768 KB Output is correct
9 Correct 18 ms 1280 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 14 ms 1024 KB Output is correct
12 Correct 21 ms 1280 KB Output is correct
13 Correct 16 ms 1280 KB Output is correct
14 Correct 16 ms 1280 KB Output is correct
15 Correct 50 ms 3060 KB Output is correct
16 Correct 53 ms 2932 KB Output is correct
17 Correct 48 ms 2840 KB Output is correct
18 Correct 43 ms 2712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 9 ms 768 KB Output is correct
9 Correct 18 ms 1280 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 14 ms 1024 KB Output is correct
12 Correct 21 ms 1280 KB Output is correct
13 Correct 16 ms 1280 KB Output is correct
14 Correct 16 ms 1280 KB Output is correct
15 Correct 50 ms 3060 KB Output is correct
16 Correct 53 ms 2932 KB Output is correct
17 Correct 48 ms 2840 KB Output is correct
18 Correct 43 ms 2712 KB Output is correct
19 Incorrect 51 ms 2996 KB Wrong Answer [2]
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 9 ms 768 KB Output is correct
9 Correct 18 ms 1280 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 14 ms 1024 KB Output is correct
12 Correct 21 ms 1280 KB Output is correct
13 Correct 16 ms 1280 KB Output is correct
14 Correct 16 ms 1280 KB Output is correct
15 Correct 50 ms 3060 KB Output is correct
16 Correct 53 ms 2932 KB Output is correct
17 Correct 48 ms 2840 KB Output is correct
18 Correct 43 ms 2712 KB Output is correct
19 Incorrect 51 ms 2996 KB Wrong Answer [2]
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 9 ms 768 KB Output is correct
9 Correct 18 ms 1280 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 14 ms 1024 KB Output is correct
12 Correct 21 ms 1280 KB Output is correct
13 Correct 16 ms 1280 KB Output is correct
14 Correct 16 ms 1280 KB Output is correct
15 Correct 50 ms 3060 KB Output is correct
16 Correct 53 ms 2932 KB Output is correct
17 Correct 48 ms 2840 KB Output is correct
18 Correct 43 ms 2712 KB Output is correct
19 Incorrect 51 ms 2996 KB Wrong Answer [2]
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 9 ms 768 KB Output is correct
9 Correct 18 ms 1280 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 14 ms 1024 KB Output is correct
12 Correct 21 ms 1280 KB Output is correct
13 Correct 16 ms 1280 KB Output is correct
14 Correct 16 ms 1280 KB Output is correct
15 Correct 50 ms 3060 KB Output is correct
16 Correct 53 ms 2932 KB Output is correct
17 Correct 48 ms 2840 KB Output is correct
18 Correct 43 ms 2712 KB Output is correct
19 Incorrect 51 ms 2996 KB Wrong Answer [2]
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 9 ms 768 KB Output is correct
9 Correct 18 ms 1280 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 14 ms 1024 KB Output is correct
12 Correct 21 ms 1280 KB Output is correct
13 Correct 16 ms 1280 KB Output is correct
14 Correct 16 ms 1280 KB Output is correct
15 Correct 50 ms 3060 KB Output is correct
16 Correct 53 ms 2932 KB Output is correct
17 Correct 48 ms 2840 KB Output is correct
18 Correct 43 ms 2712 KB Output is correct
19 Incorrect 51 ms 2996 KB Wrong Answer [2]
20 Halted 0 ms 0 KB -