QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#224264 | #7179. Fischer's Chess Guessing Game | dozicc | WA | 3ms | 3564kb | C++14 | 3.9kb | 2023-10-23 00:53:04 | 2023-10-23 00:53:05 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<pair<string, int> >permutation;
map<char, int>check;
ll cnt[960][9], c=0;
void gen(int k, string s)
{
if(k==8)
{
int pl1=0, pl2=0, pp1=0, pp2=0;
for(int i=0; i<8; i++)
{
if(s[i]=='B')
{
if(pl1!=0)pl2=i+1;
else pl1=i+1;
}
if(s[i]=='K')
{
if(pp1!=0 and pp2!=0)return;
if(pp1==0 and pp2==0)return;
}
if(s[i]=='R')
{
if(pp1!=0)pp2=i+1;
else pp1=i+1;
}
}
if(pl1%2==pl2%2)return;
permutation.push_back({s, c});
c++;
return;
}
if(check['R']<2)
{
check['R']++; s+='R';
gen(k+1, s); check['R']--; s.pop_back();
}
if(check['B']<2)
{
check['B']++; s+='B';
gen(k+1, s); check['B']--; s.pop_back();
}
if(check['N']<2)
{
check['N']++; s+='N';
gen(k+1, s); check['N']--; s.pop_back();
}
if(check['K']<1)
{
check['K']++; s+='K';
gen(k+1, s); check['K']--; s.pop_back();
}
if(check['Q']<1)
{
check['Q']++; s+='Q';
gen(k+1, s); check['Q']--; s.pop_back();
}
return;
}
int main()
{
string str;
getline(cin, str);
gen(0, "");
for(int i=0; i<960; i++)
{
for(int j=i+1; j<960; j++)
{
int br=0;
for(int l=0; l<8; l++)
{
if(permutation[i].first[l]==permutation[j].first[l])br++;
}
cnt[i][br]++; cnt[j][br]++;
}
}
int idx=-1, mini=INT_MAX;
for(int i=0; i<960; i++)
{
ll lmax=0;
for(int j=0; j<9; j++)lmax=max(lmax, cnt[i][j]);
if(lmax<mini){mini=lmax; idx=i;}
}
cout<<permutation[idx].first<<endl;
int ans; cin>>ans;
if(ans==8){cout<<"END"; return 0;}
vector<pair<string, int> >smor;
/// ---------------------prvo------------------------ ///
int t=2;
while(t--)
{for(int i=0; i<permutation.size(); i++)
{
int br=0;
for(int l=0; l<8; l++)
{
if(permutation[i].first[l]==permutation[idx].first[l])br++;
}
if(br==ans)smor.push_back(permutation[i]);
}
idx=-1, mini=INT_MAX;
for(int i=0; i<smor.size(); i++)
{
ll lmax=0;
for(int j=0; j<9; j++)lmax=max(lmax, cnt[smor[i].second][j]);
if(lmax<mini){mini=lmax; idx=i;}
}
cout<<smor[idx].first<<endl;
permutation.clear();
cin>>ans;
if(ans==8){cout<<"END"; return 0;}
for(int i=0; i<smor.size(); i++)
{
int br=0;
for(int l=0; l<8; l++)
{
if(smor[i].first[l]==smor[idx].first[l])br++;
}
if(br==ans)permutation.push_back(smor[i]);
}
idx=-1, mini=INT_MAX;
for(int i=0; i<permutation.size(); i++)
{
ll lmax=0;
for(int j=0; j<9; j++)lmax=max(lmax, cnt[permutation[i].second][j]);
if(lmax<mini){mini=lmax; idx=i;}
}
cout<<permutation[idx].first<<endl;
smor.clear();
cin>>ans;
if(ans==8){cout<<"END"; return 0;}
}
for(int i=0; i<permutation.size(); i++)
{
int br=0;
for(int l=0; l<8; l++)
{
if(permutation[i].first[l]==permutation[idx].first[l])br++;
}
if(br==ans)smor.push_back(permutation[i]);
}
idx=-1, mini=INT_MAX;
for(int i=0; i<smor.size(); i++)
{
ll lmax=0;
for(int j=0; j<9; j++)lmax=max(lmax, cnt[smor[i].second][j]);
if(lmax<mini){mini=lmax; idx=i;}
}
cout<<smor[idx].first<<endl;
permutation.clear();
cin>>ans;
if(ans==8){cout<<"END"; return 0;}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 3564kb
input:
GAME 1 4 4 5 4 8 END
output:
RQKBBNRN RKQNBBRN RKQBBNNR RKQBRNBN RKRBBQNN END
result:
ok (c) correct after 1 tests, max moves 5 (1 test case)
Test #2:
score: -100
Wrong Answer
time: 3ms
memory: 3564kb
input:
GAME 1 4 4 5 4 8 GAME 2
output:
RQKBBNRN RKQNBBRN RKQBBNNR RKQBRNBN RKRBBQNN END
result:
wrong answer (i) illegal position "END" (game 2, guess 1) (test case 2)