답안 #522451

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
522451 2022-02-05T04:13:19 Z amunduzbaev Mouse (info1cup19_mouse) C++17
컴파일 오류
0 ms 0 KB
//~ #include "grader.h"

#include <bits/stdc++.h>
using namespace std;

#define ar array

int n;
vector<int> todo, a, B;

//~ int query(vector<int> a){
	//~ assert((int)a.size() == n);
	//~ int res = 0;
	//~ for(int i=0;i<n;i++){
		//~ res += (a[i] == B[i]);
	//~ } 
	//~ if(res == n){
		//~ cout<<"YES\n";
		//~ exit(0);
	//~ }
	//~ return res;
}

int check(int x){
	assert(2 * x <= (int)todo.size());
	for(int i=0;i+1<2*x;i+=2){
		swap(a[todo[i]], a[todo[i+1]]);
	}
	
	int r = query(a);
	if(r == n) exit(0);
	for(int i=0;i+1<2*x;i+=2){
		swap(a[todo[i]], a[todo[i+1]]);
	} return r;
}

void solve(int N) { n = N;
	mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
	
	a.resize(n);
	iota(a.begin(), a.end(), 1);
	while(1){
		shuffle(a.begin(), a.end(), rnd);
		int q = query(a);
		if(q == n) return;
		if(!q) break;
	}
	
	vector<int> used(n);
	int don = 0;
	while(1){
		//~ for(int i=0;i<n;i++){
			//~ cout<<used[i]<<" ";
		//~ } cout<<endl;
		//~ for(int i=0;i<n;i++){
			//~ cout<<a[i]<<" ";
		//~ } cout<<endl;
		
		todo.clear();
		for(int i=0;i<n;i++){
			if(used[i]) continue;
			todo.push_back(i);
		}
		
		shuffle(todo.begin(), todo.end(), rnd);
		int half = (int)todo.size() / 2;
		if(check(half) == don) continue;
		//~ cout<<"here"<<endl;
		int l = 1, r = half;
		while(l < r){
			int m = (l + r) >> 1;
			if(check(m) > don){
				r = m;
			} else {
				l = m + 1;
			}
		}
		int i = todo[l<<1], j = todo[l<<1|1];
		swap(a[i], a[j]);
		int cost = query(a);
		if(cost == n) return;
		if(cost == don + 2){
			used[i] = used[j] = 1; don += 2;
		} else {
			int p = -1;
			for(int l=0;l<n;l++){
				if(used[l] || i == l || j == l) continue;
				p = l; break;
			}
			
			assert(~p);
			swap(a[i], a[p]);
			int tmp = query(a);
			if(tmp == n) return;
			swap(a[i], a[p]);
			if(tmp < cost) used[i] = 1;
			else used[j] = 1;
			don++;
		}
	}
}

/*

8
3 6 5 7 8 1 4 2

*/

//~ signed main(){
	//~ int n; cin>>n;
	//~ B.resize(n);
	//~ for(int i=0;i<n;i++) cin>>B[i];
	//~ solve(n);
}
	

Compilation message

mouse.cpp:22:1: error: expected declaration before '}' token
   22 | }
      | ^
mouse.cpp: In function 'int check(int)':
mouse.cpp:30:10: error: 'query' was not declared in this scope
   30 |  int r = query(a);
      |          ^~~~~
mouse.cpp: In function 'void solve(int)':
mouse.cpp:44:11: error: 'query' was not declared in this scope
   44 |   int q = query(a);
      |           ^~~~~
mouse.cpp:80:14: error: 'query' was not declared in this scope
   80 |   int cost = query(a);
      |              ^~~~~
mouse.cpp: At global scope:
mouse.cpp:115:1: error: expected declaration before '}' token
  115 | }
      | ^