結果

問題 No.2848 Birthday Hit and Blow
ユーザー kotatsugamekotatsugame
提出日時 2024-08-23 22:15:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,694 bytes
コンパイル時間 1,292 ms
コンパイル使用メモリ 94,068 KB
実行使用メモリ 40,396 KB
平均クエリ数 2.00
最終ジャッジ日時 2024-08-23 22:15:53
合計ジャッジ時間 4,900 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
24,812 KB
testcase_01 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<cassert>
#include<cstdlib>
using namespace std;
pair<int,int>calc(string SQ,string SA)
{
	int H=0,B=0;
	for(int i=0;i<4;i++)
	{
		if(SQ[i]==SA[i])H++;
		for(int j=0;j<4;j++)if(i!=j&&SQ[i]==SA[j])B++;
	}
	return make_pair(H,B);
}
string ans;
vector<string>SQs;
void dfs(vector<string>SAs,int t)
{
	if(SAs.size()==1)
	{
		//output
		cout<<"! "<<SAs[0]<<endl;
		int a;cin>>a;if(a==-1)exit(0);
		return;
	}
	assert(t<6);
	int mx_min=1e9;
	string SSQ;
	for(string SQ:SQs)
	{
		map<pair<int,int>,vector<string> >mp;
		int mx=0;
		for(string SA:SAs)
		{
			auto p=calc(SQ,SA);
			mp[p].push_back(SA);
			mx=max(mx,(int)mp[p].size());
		}
		if(mx_min>mx)
		{
			mx_min=mx;
			SSQ=SQ;
		}
	}
	cout<<"? "<<SSQ<<endl;
	pair<int,int>ret;
	cin>>ret.first>>ret.second;
	//ret=calc(SSQ,ans);
	vector<string>nSAs;
	for(string SA:SAs)if(calc(SSQ,SA)==ret)nSAs.push_back(SA);
	dfs(nSAs,t+1);
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	{
		for(int v=0;v<=9999;v++)
		{
			string t="";
			t+=v/1000+'0';
			t+=v/100%10+'0';
			t+=v/10%10+'0';
			t+=v%10+'0';
			string st=t;
			sort(st.begin(),st.end());
			if(st[0]!=st[1]&&st[1]!=st[2]&&st[2]!=st[3])SQs.push_back(t);
		}
		assert(SQs.size()==10*9*8*7);
	}
	vector<string>SAs;
	{
		for(int M=1;M<=12;M++)
		{
			int L=M==2?29:L==4||L==6||L==9||L==11?30:31;
			for(int D=1;D<=L;D++)
			{
				string t="";
				t+=M/10+'0';
				t+=M%10+'0';
				t+=D/10+'0';
				t+=D%10+'0';
				string st=t;
				sort(st.begin(),st.end());
				if(st[0]!=st[1]&&st[1]!=st[2]&&st[2]!=st[3])SAs.push_back(t);
			}
		}
	}
	int T;cin>>T;
	for(;T--;)
	{
		//cin>>ans;
		dfs(SAs,0);
	}
}
0