QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#226461 | #7179. Fischer's Chess Guessing Game | sofija6 | TL | 0ms | 0kb | C++17 | 2.4kb | 2023-10-25 23:20:16 | 2023-10-25 23:20:16 |
answer
#include <bits/stdc++.h>
#define ll int
using namespace std;
vector<string> v;
vector<pair<string,ll> > S;
vector<string> cor,cor1;
ll cnt[10]={0},cur=0,diff,maxx;
string ans;
void Get_Min()
{
maxx=INT_MAX;
set<string> ss;
for (auto i : cor)
{
bool yes=true;
for (auto j : S)
{
ll num=0;
for (ll p=0;p<8;p++)
num+=(i[p]!=j.first[p]);
if (num!=j.second)
yes=false;
}
if (yes)
cor1.push_back(i);
}
cor=cor1;
cor1.clear();
for (auto i : cor)
{
for (ll j=0;j<10;j++)
cnt[j]=0;
cur=0;
for (auto l : cor)
{
diff=0;
for (ll p=0;p<8;p++)
diff+=(i[p]!=l[p]);
cnt[diff]++;
cur=max(cur,cnt[diff]);
}
if (cur<maxx)
{
ans=i;
maxx=cur;
}
}
return;
}
ll b,p,k,n,q,r,prevv;
string s;
void Create()
{
if ((ll)s.size()==8)
{
v.push_back(s);
return;
}
if (!b || (b==1 && p!=s.size()%2))
{
b++;
prevv=p;
p=s.size()%2;
s+='B';
Create();
p=prevv;
b--;
s.pop_back();
}
if (!k && r==1)
{
s+='K';
k++;
Create();
k--;
s.pop_back();
}
if (n!=2)
{
s+='N';
n++;
Create();
n--;
s.pop_back();
}
if (!q)
{
s+='Q';
q++;
Create();
q--;
s.pop_back();
}
if (!r || (r==1 && k==1))
{
s+='R';
r++;
Create();
r--;
s.pop_back();
}
return;
}
int main()
{
string x="";
Create();
ll a;
Get_Min();
string xx=ans;
while (true)
{
if (x=="")
cin >> x;
cin >> n;
S.clear();
cor=v;
ans=xx;
while (true)
{
cout << ans << "\n";
cin >> a;
a=8-a;
if (!a)
{
cin >> x;
if (x=="END")
return 0;
break;
}
S.push_back({ans,a});
Get_Min();
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
GAME 1