結果
| 問題 |
No.2848 Birthday Hit and Blow
|
| コンテスト | |
| ユーザー |
kmjp
|
| 提出日時 | 2024-08-24 00:53:57 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,411 bytes |
| コンパイル時間 | 2,740 ms |
| コンパイル使用メモリ | 220,148 KB |
| 最終ジャッジ日時 | 2025-02-24 00:30:44 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | RE * 1 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------
int M[]={31,29,31,30,31,30,31,31,30,31,30,31};
vector<string> bcand,cand;
int T;
map<pair<string,string>,pair<int,int>> memo;
pair<int,int> hit(string a,string b) {
if(memo.count({a,b})==0) {
int hit=0,blow=0;
int x,y;
FOR(x,4) FOR(y,4) if(a[x]==b[y]) {
if(x==y) hit++;
else blow++;
}
memo[{a,b}]={hit,blow};
}
return memo[{a,b}];
}
string best() {
int a,b,c,d;
int num=101010;
string be;
int step=0;
FOR(a,10) FOR(b,10) FOR(c,10) FOR(d,10) {
if(a==b) continue;
if(a==c) continue;
if(a==d) continue;
if(b==c) continue;
if(b==d) continue;
if(c==d) continue;
step++;
if(step>=200) break;
string X="0000";
X[0]+=a;
X[1]+=b;
X[2]+=c;
X[3]+=d;
map<pair<int,int>,int> M;
int ma=0;
FORR(c,cand) {
auto p=hit(c,X);
M[p]++;
ma=max(ma,M[p]);
if(ma>=num) break;
}
if(ma<num) {
num=ma;
be=X;
}
}
return be;
}
void solve() {
int i,j,k,l,r,x,y; string s;
FOR(i,12) {
FOR(j,M[i]) {
string S="0000";
S[0]+=(i+1)/10;
S[1]+=(i+1)%10;
S[2]+=(j+1)/10;
S[3]+=(j+1)%10;
if(S[0]==S[1]) continue;
if(S[0]==S[2]) continue;
if(S[0]==S[3]) continue;
if(S[1]==S[2]) continue;
if(S[1]==S[3]) continue;
if(S[2]==S[3]) continue;
bcand.push_back(S);
}
}
cin>>T;
while(T--) {
cand=bcand;
//cin>>s;
k=0;
while(cand.size()>1) {
k++;
string X=best();
cout<<"? "<<X<<endl;
cin>>x>>y;
assert(x!=-1);
vector<string> nex;
FORR(c,cand) if(hit(X,c)==make_pair(x,y)) nex.push_back(c);
cand=nex;
}
assert(k<=4);
cout<<"! "<<cand[0]<<endl;
cin>>x;
assert(x==0);
}
}
int main(int argc,char** argv){
string s;int i;
if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
cout.tie(0); solve(); return 0;
}
kmjp