제출 #1305190

#제출 시각아이디문제언어결과실행 시간메모리
1305190salmonLight Bulbs (EGOI24_lightbulbs)C++20
84.17 / 100
61 ms456 KiB
#include <bits/stdc++.h>
using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

int N;

bool ans[110][110];
bool ansh[110][110];
bool ansv[110][110];
int buf;
vector<int> h,v;

void print(){
	printf("?\n");
	
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++) printf("%d",(int)ans[i][j]);
		printf("\n");
	}
	
	fflush(stdout);
}

void answer(){
	printf("!\n");
	
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++) printf("%d",(int)ans[i][j]);
		printf("\n");
	}
	
	fflush(stdout);
}

bool check(int i, int j){
	if(ansh[0][0]){
		for(int i = 0; i < N; i++){
			for(int j = 0; j < N; j++){
				ans[i][j] = 0;
			}
		}
		
		ans[0][0] = 1;
		ans[i][j] = 1;
		
		print();
		
		int h;
		scanf(" %d",&h);
		
		if(h % N == 0) return 1;
		return 0;
	}
	else{
		for(int i = 0; i < N; i++){
			for(int j = 0; j < N; j++){
				ans[i][j] = 0;
			}
		}
		
		ans[0][0] = 1;
		ans[i][j] = 1;
		
		print();
		
		int h;
		scanf(" %d",&h);
		
		if(h % N == 0) return 0;
		return 1;
	}
}

int main(){
	
	scanf(" %d",&N);
	
	for(int i = 0; i < N; i++){
		h.push_back(i);
		v.push_back(i);
	}
	
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			ans[i][j] = false;
			ansh[i][j] = false;
			ansv[i][j] = false;
		}
	}
	
	
	for(int j = 0; j < N; j++){
		ans[0][j] = true; 
	}
	
	print();
	scanf(" %d",&buf);
	
	if(buf == N * N){
		answer();
		return 0;
	}
	
	int num1 = buf;
	
	ans[0][0] = false;
	
	print();
	scanf(" %d",&buf);
	
	if(buf % N == 0 && buf != N){
		ansh[0][0] = 1;
		h.erase(h.begin(),h.begin() + 1);
	}
	else{
		if(buf == num1){
			ansh[0][0] = 1;
			h.erase(h.begin(),h.begin() + 1);
		}
		else{
			ansv[0][0] = 1;
			v.erase(v.begin(),v.begin() + 1);
		}
	}
	
	while(!h.empty() && !v.empty()){
		//for(int i : h) printf("%d ",i);
		//printf("\n");
		//for(int i : v) printf("%d ",i);
		//printf("\n\n");
		
		int x = rng() % h.size();
		int x1 = rng() % h.size();
		int y = rng() % v.size();
		int y1 = rng() % v.size();
		
		if(h.size() == 1 && v.size() == 1){			
			if(check(h[x],v[y])){
				ansh[h[x]][v[y]] = 1;
				
				h.erase(h.begin() + x, h.begin() + x + 1);
			}
			else{
				ansv[h[x]][v[y]] = 1;
				
				v.erase(v.begin() + y, v.begin() + y + 1);
			}
		}
		else if(h.size() == 1 || (v.size() >= 2 && rng() % 2)){
			
			while(y == y1) y1 = rng() % v.size();
			
			for(int i = 0; i < N; i++){
				for(int j = 0; j < N; j++){
					ans[i][j] = 0;
				}
			}
			
			ans[h[x]][v[y]] = 1;
			ans[h[x]][v[y1]] = 1;
			
			print();
			scanf(" %d",&buf);
			
			if(buf == N){
				ansh[h[x]][v[y]] = 1;
				
				h.erase(h.begin() + x, h.begin() + x + 1);
			}
			else if(buf == N * 2){
				if(y1 < y) swap(y,y1);
				
				ansv[h[x]][v[y]] = 1;
				ansv[h[x]][v[y1]] = 1;
				
				v.erase(v.begin() + y1, v.begin() + y1 + 1);
				v.erase(v.begin() + y, v.begin() + y + 1);
			}
			else{
				if(check(h[x],v[y1])){
					ansh[h[x]][v[y1]] = 1;	
					
					ansv[h[x]][v[y]] = 1;
					
					h.erase(h.begin() + x, h.begin() + x + 1);
					v.erase(v.begin() + y, v.begin() + y + 1);
				}
				else{
					ansv[h[x]][v[y1]] = 1;
					
					ansh[h[x]][v[y]] = 1;	
					
					v.erase(v.begin() + y1, v.begin() + y1 + 1);
					h.erase(h.begin() + x, h.begin() + x + 1);
				}
			}
			
		}
		else{
			
			while(x == x1) x1 = rng() % h.size();
			
			for(int i = 0; i < N; i++){
				for(int j = 0; j < N; j++){
					ans[i][j] = 0;
				}
			}
			
			ans[h[x]][v[y]] = 1;
			ans[h[x1]][v[y]] = 1;
			
			print();
			scanf(" %d",&buf);
			
			if(buf == N){
				ansv[h[x]][v[y]] = 1;
				
				v.erase(v.begin() + y, v.begin() + y + 1);
			}
			else if(buf == N * 2){
				if(x1 < x) swap(x,x1);
				
				ansh[h[x]][v[y]] = 1;
				ansh[h[x1]][v[y]] = 1;
				
				h.erase(h.begin() + x1, h.begin() + x1 + 1);
				h.erase(h.begin() + x, h.begin() + x + 1);
			}
			else{
				if(check(h[x1],v[y])){
					ansh[h[x1]][v[y]] = 1;	
					
					ansv[h[x]][v[y]] = 1;
					
					h.erase(h.begin() + x1, h.begin() + x1 + 1);
					v.erase(v.begin() + y, v.begin() + y + 1);
				}
				else{
					ansv[h[x1]][v[y]] = 1;
					
					ansh[h[x]][v[y]] = 1;	
					
					v.erase(v.begin() + y, v.begin() + y + 1);
					h.erase(h.begin() + x, h.begin() + x + 1);
				}
			}
			
		}
		
	}
	
	if(h.empty()){
		for(int i = 0; i < N; i++){
			for(int j = 0; j < N; j++){
				ans[i][j] = ansh[i][j];
			}
		}
	}
	else if(v.empty()){
		for(int i = 0; i < N; i++){
			for(int j = 0; j < N; j++){
				ans[i][j] = ansv[i][j];
			}
		}
	}
	
	answer();
}	

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'bool check(int, int)':
Main.cpp:50:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |                 scanf(" %d",&h);
      |                 ~~~~~^~~~~~~~~~
Main.cpp:68:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |                 scanf(" %d",&h);
      |                 ~~~~~^~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:77:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |         scanf(" %d",&N);
      |         ~~~~~^~~~~~~~~~
Main.cpp:98:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |         scanf(" %d",&buf);
      |         ~~~~~^~~~~~~~~~~~
Main.cpp:110:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  110 |         scanf(" %d",&buf);
      |         ~~~~~^~~~~~~~~~~~
Main.cpp:164:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  164 |                         scanf(" %d",&buf);
      |                         ~~~~~^~~~~~~~~~~~
Main.cpp:214:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  214 |                         scanf(" %d",&buf);
      |                         ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...