답안 #758046

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
758046 2023-06-14T05:42:40 Z alexander707070 Unscrambling a Messy Bug (IOI16_messy) C++14
100 / 100
4 ms 500 KB
#include<bits/stdc++.h>
#include "messy.h"
#define MAXN 10007
using namespace std;
 
int nn;
string curr,zero;
int perm[MAXN];
bool in[MAXN];
vector<int> ans,v;
 
void question(){
	curr="";
	for(int i=0;i<nn;i++){
		if(in[i])curr+="1";
		else curr+="0";
	}
	add_element(curr);
}

void ask(int l,int r){
    if(l==r)return;

	int mid=(l+r)/2;
	for(int i=l;i<=mid;i++){
		in[i]=true;
		question();
		in[i]=false;
	}

	for(int i=mid+1;i<=r;i++)in[i]=true;
	ask(l,mid);
	for(int i=mid+1;i<=r;i++)in[i]=false;

	for(int i=l;i<=mid;i++)in[i]=true;
	ask(mid+1,r);
	for(int i=l;i<=mid;i++)in[i]=false;
}

bool answer(){
	curr="";
	for(int i=0;i<nn;i++){
		if(in[i])curr+="1";
		else curr+="0";
	}
	return check_element(curr);
}

void solve(int l,int r,vector<int> poss){
	if(l==r){
		perm[poss[0]]=l; return;
	}

	vector<int> ll,rr;
	for(int i=0;i<poss.size();i++){
		in[poss[i]]=true;		

		if(answer())ll.push_back(poss[i]);
		else rr.push_back(poss[i]);

		in[poss[i]]=false;
	}

	int mid=(l+r)/2;

	for(int i:rr)in[i]=true;
	solve(l,mid,ll);
	for(int i:rr)in[i]=false;

	for(int i:ll)in[i]=true;
	solve(mid+1,r,rr);
	for(int i:ll)in[i]=false;
}

vector<int> restore_permutation(int N, int w, int r){
    nn=N;
	ask(0,nn-1);
	compile_set();

	for(int i=0;i<nn;i++)v.push_back(i);
	solve(0,nn-1,v);

	for(int i=0;i<nn;i++){
		ans.push_back(perm[i]);
	}

	return ans;
}
 
/*
int main(){
 
}
*/

Compilation message

messy.cpp: In function 'void solve(int, int, std::vector<int>)':
messy.cpp:55:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |  for(int i=0;i<poss.size();i++){
      |              ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB n = 8
2 Correct 1 ms 212 KB n = 8
3 Correct 1 ms 212 KB n = 8
4 Correct 1 ms 340 KB n = 8
5 Correct 1 ms 212 KB n = 8
6 Correct 1 ms 212 KB n = 8
7 Correct 1 ms 212 KB n = 8
8 Correct 1 ms 212 KB n = 8
9 Correct 1 ms 212 KB n = 8
10 Correct 1 ms 212 KB n = 8
11 Correct 1 ms 212 KB n = 8
12 Correct 1 ms 212 KB n = 8
13 Correct 1 ms 212 KB n = 8
14 Correct 1 ms 308 KB n = 8
15 Correct 1 ms 212 KB n = 8
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB n = 32
2 Correct 1 ms 212 KB n = 32
3 Correct 1 ms 304 KB n = 32
4 Correct 1 ms 212 KB n = 32
5 Correct 1 ms 304 KB n = 32
6 Correct 1 ms 212 KB n = 32
7 Correct 1 ms 212 KB n = 32
8 Correct 1 ms 340 KB n = 32
9 Correct 1 ms 212 KB n = 32
10 Correct 1 ms 212 KB n = 32
11 Correct 1 ms 304 KB n = 32
12 Correct 1 ms 212 KB n = 32
13 Correct 1 ms 212 KB n = 32
14 Correct 1 ms 212 KB n = 32
15 Correct 1 ms 212 KB n = 32
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB n = 32
2 Correct 1 ms 212 KB n = 32
3 Correct 1 ms 212 KB n = 32
4 Correct 1 ms 212 KB n = 32
5 Correct 1 ms 212 KB n = 32
6 Correct 1 ms 212 KB n = 32
7 Correct 1 ms 212 KB n = 32
8 Correct 1 ms 296 KB n = 32
9 Correct 1 ms 212 KB n = 32
10 Correct 1 ms 212 KB n = 32
11 Correct 1 ms 212 KB n = 32
12 Correct 1 ms 300 KB n = 32
13 Correct 1 ms 308 KB n = 32
14 Correct 1 ms 308 KB n = 32
15 Correct 1 ms 300 KB n = 32
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 432 KB n = 128
2 Correct 3 ms 432 KB n = 128
3 Correct 3 ms 468 KB n = 128
4 Correct 3 ms 468 KB n = 128
5 Correct 3 ms 468 KB n = 128
6 Correct 3 ms 468 KB n = 128
7 Correct 3 ms 432 KB n = 128
8 Correct 3 ms 468 KB n = 128
9 Correct 3 ms 468 KB n = 128
10 Correct 3 ms 468 KB n = 128
11 Correct 3 ms 468 KB n = 128
12 Correct 3 ms 468 KB n = 128
13 Correct 3 ms 468 KB n = 128
14 Correct 3 ms 468 KB n = 128
15 Correct 2 ms 468 KB n = 128
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 436 KB n = 128
2 Correct 3 ms 432 KB n = 128
3 Correct 3 ms 500 KB n = 128
4 Correct 4 ms 468 KB n = 128
5 Correct 3 ms 468 KB n = 128
6 Correct 3 ms 468 KB n = 128
7 Correct 3 ms 468 KB n = 128
8 Correct 2 ms 468 KB n = 128
9 Correct 3 ms 468 KB n = 128
10 Correct 3 ms 468 KB n = 128
11 Correct 3 ms 468 KB n = 128
12 Correct 2 ms 468 KB n = 128
13 Correct 3 ms 468 KB n = 128
14 Correct 3 ms 468 KB n = 128
15 Correct 3 ms 468 KB n = 128