結果

問題 No.1306 Exactly 2 Digits
ユーザー ransewhaleransewhale
提出日時 2020-12-15 09:31:41
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,061 bytes
コンパイル時間 2,360 ms
コンパイル使用メモリ 96,528 KB
最終ジャッジ日時 2025-01-17 00:59:30
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 114 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

std::map<std::vector<int>, int > dic;
std::vector<int> v(100);
int ans[2525],s[2525],t[2525],x,y,n;
bool used[55][55];

bool check(int p, int q){
	return (1<=x-p && x-p <n && 0<=y-q && y-q < n && (!used[x-p][y-q])); 
}

int main(void){
	int i,j,p,q,m,z;
	std::cin >> n; m = n*n-n;
	for(x=1; x<n; ++x){
		for(y=0; y<n; ++y){
			std::fill(v.begin(),v.end(),0);
			for(i=1; i<n; ++i){
				for(j=0; j<n; ++j){
					p = x-i; q = y-j;
					++v[p+50]; ++v[q+50];
				}
			}
			v[50] -= 2;
			dic[v] = x*n+y;
		}
	}
	std::fill(v.begin(),v.end(),0);
	for(i=2; i<=m; ++i){
		std::cout << "? 1 " << i << std::endl;
		std::cin >> s[i] >> t[i];
		++v[s[i]+50]; ++v[t[i]+50];
	}
	ans[1] = dic[v];
	x = ans[1]/n; y = ans[1]%n;
	z = 1; used[x][y] = true;
	for(i=2; i<=m; ++i){
		if(s[i] == std::min(x-1,y) && t[i] == std::max(x-1,y)){
			z = i;
		}
	}
	for(i=2; i<=m; ++i){
		if(s[i] == t[i]){
			used[x-s[i]][y-t[i]] = true;
			ans[i] = (x-s[i])*n+(y-t[i]);
			continue;
		}
		if(!check(s[i],t[i])){
			used[x-t[i]][y-s[i]] = true;
			ans[i] = (x-t[i])*n+(y-s[i]);
			continue;
		}
		if(!check(t[i],s[i])){
			used[x-s[i]][y-t[i]] = true;
			ans[i] = (x-s[i])*n+(y-t[i]);
			continue;
		}
		std::cout << "? " << i << " " << z << std::endl;
		std::cin >> p >> q;
		++p;
		if(s[i] == std::min(x-p,y-q) && t[i] == std::max(x-p,y-q)){
			used[p][q] = true;
			ans[i] = p*n+q;
			continue;
		}
		--p; std::swap(p,q); ++p;
		if(s[i] == std::min(x-p,y-q) && t[i] == std::max(x-p,y-q)){
			used[p][q] = true;
			ans[i] = p*n+q;
			continue;
		}
		--p;
	}
	std::cout << "!";
	for(i=1; i<=m; ++i){
		std::cout << " " << ans[i];
	}
	std::cout << std::endl;
	return 0;
}
0