Submission #120689

# Submission time Handle Problem Language Result Execution time Memory
120689 2019-06-25T08:22:45 Z 임유진(#2961) Minerals (JOI19_minerals) C++14
6 / 100
1000 ms 21208 KB
#include "minerals.h"
#include<vector>
#include<map>

using namespace std;

#define MAXN 43005

int q[2*MAXN];
vector<int> L, R;
vector<bool> chk;
map<vector<bool>, int> m;

int gq(int x, bool skip){
	chk[x]=!chk[x];
	if(skip&&m.find(chk)!=m.end()){
		int t=m[chk];
		chk[x]=!chk[x];
		return t;
	}
	return m[chk]=Query(x);
}

vector<int> f(vector<int> lidx, int rs, int re, bool in){
	//printf("[%d %d]", rs, re);
	//for(auto a:lidx) printf("%d ", a);
	//printf("\n");
	if(rs==re) return lidx;
	int m=(rs+re)/2;
	vector<int> q(re-rs+2), lef, rig;
	for(int i=m+1; i<=re; i++) q[re-rs+1]=gq(R[i], false);
	for(int i=re-rs; i>0; i--){
		chk[L[lidx[i]]]=!chk[L[lidx[i]]];
		bool b=(::m.find(chk)!=::m.end());
		chk[L[lidx[i]]]=!chk[L[lidx[i]]];
		q[i]=gq(L[lidx[i]], true);
		if(in==true){
			if(q[i]!=q[i+1]) rig.push_back(lidx[i]);
			else lef.push_back(lidx[i]);
		}
		else{
			if(q[i]!=q[i+1]) lef.push_back(lidx[i]);
			else rig.push_back(lidx[i]);
		}
		if(b) q[i]=q[i+1];
	}
	if(lef.size()<=rig.size()) lef.push_back(lidx[0]);
	else rig.push_back(lidx[0]);
	vector<int> v1, v2;
	v1=f(lef, rs, m, in);
	v2=f(rig, m+1, re, !in);
	for(auto a:v2) v1.push_back(a);
	return v1;
}

void Solve(int N) {
	for(int i=1; i<=2*N; i++) chk.push_back(false);
	for(int i=1; i<=2*N; i++){
		q[i]=gq(i, false);
		if(q[i]>q[i-1]) L.push_back(i);
		else R.push_back(i);
	}
	//for(auto a:L) printf("%d ", a);
	//printf("\n");
	vector<int> v(N);
	for(int i=0; i<N; i++) v[i]=i;
	vector<int> ans=f(v, 0, N-1, true);
	//for(auto a:ans) printf("{%d}", a);
	for(int i=0; i<N; i++) Answer(L[ans[i]], R[i]);
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 594 ms 6240 KB Output is correct
2 Execution timed out 2780 ms 21208 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 594 ms 6240 KB Output is correct
6 Execution timed out 2780 ms 21208 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 594 ms 6240 KB Output is correct
6 Execution timed out 2780 ms 21208 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 594 ms 6240 KB Output is correct
6 Execution timed out 2780 ms 21208 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 594 ms 6240 KB Output is correct
6 Execution timed out 2780 ms 21208 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 594 ms 6240 KB Output is correct
6 Execution timed out 2780 ms 21208 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 594 ms 6240 KB Output is correct
6 Execution timed out 2780 ms 21208 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 594 ms 6240 KB Output is correct
6 Execution timed out 2780 ms 21208 KB Time limit exceeded
7 Halted 0 ms 0 KB -