QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#224525 | #7179. Fischer's Chess Guessing Game | dozicc | TL | 0ms | 3828kb | C++14 | 5.3kb | 2023-10-23 03:28:39 | 2023-10-23 03:28:39 |
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()
{
gen(0, "");
string st;
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]++;
}
}
getline(cin, st);
while(true)
{
vector<pair<string, int> >perm;
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;}
perm.push_back(permutation[i]);
}
///----------IZLAZ 1-----------///
cout<<permutation[idx].first<<endl;
int ans; cin>>ans;
if(ans==8)
{
string str; int bb;
cin>>str;
if(str=="END")return 0;
else {cin>>bb; continue;}
}
vector<pair<string, int> >smor;
/// ---------------------prvo------------------------ ///
int t=2; bool b=false;
while(t--)
{
for(int i=0; i<perm.size(); i++)
{
int br=0;
for(int l=0; l<8; l++)
{
if(perm[i].first[l]==perm[idx].first[l])br++;
}
if(br==ans)smor.push_back(perm[i]);
}
//cout<<smor.size()<<"<33\n";
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;}
}
///------------IZLAZ 2--------------///
cout<<smor[idx].first<<endl;
perm.clear();
cin>>ans;
if(ans==8)
{
string str; int bb;
cin>>str;
if(str=="END")return 0;
else{cin>>bb; b=true; break;}
}
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)perm.push_back(smor[i]);
}
//cout<<perm.size()<<"<33\n";
idx=-1; mini=INT_MAX;
for(int i=0; i<perm.size(); i++)
{
ll lmax=0;
for(int j=0; j<9; j++)lmax=max(lmax, cnt[perm[i].second][j]);
if(lmax<=mini){mini=lmax; idx=i;}
}
///--------------IZLAZ 3---------------///
cout<<perm[idx].first<<endl;
smor.clear();
cin>>ans;
if(ans==8)
{
string str; int bb;
cin>>str;
if(str=="END")return 0;
else{cin>>bb; b=true; break;}
}
}
if(b)continue;
for(int i=0; i<perm.size(); i++)
{
int br=0;
for(int l=0; l<8; l++)
{
if(perm[i].first[l]==perm[idx].first[l])br++;
}
if(br==ans)smor.push_back(perm[i]);
}
//cout<<smor.size()<<"<33\n";
/*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[i].first<<endl;
}*/
///----------------IZLAZ 4------------------///
cout<<smor[0].first<<endl;
perm.clear();
cin>>ans;
if(ans==8)
{
string str; int bb;
cin>>str;
if(str=="END")return 0;
else {cin>>bb; continue;}
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3828kb
input:
GAME 1 2 4 2 3 6 8 END
output:
NRNBBKQR RQKBBNRN RQBBNNKR RKNQBNRB RKQBBRNN RKRBBQNN
result:
ok (c) correct after 1 tests, max moves 6 (1 test case)
Test #2:
score: -100
Time Limit Exceeded
input:
GAME 1 2 4 2 3 6 8 GAME 2 3 0 4 2 8 GAME 3 2 4 3 2 3 8 GAME 4 1 2 1 2 8 GAME 5 1 2 2 1 1 8 GAME 6 1 1 3 2 5 8 GAME 7 1 4 2 2 8 GAME 8 2 3 2 3 8 GAME 9 1 4 3 2 1 8 GAME 10 1 2 2 4 1 8 GAME 11 1 3 2 3 0 8 GAME 12 2 3 3 1 2 8 GAME 13 0 4 1 3 8 GAME 14 0 6 4 4 8 GAME 15 0 4 1 3 6 8 GAME 16 0 2 3 3 8 GAM...
output:
NRNBBKQR RQKBBNRN RQBBNNKR RKNQBNRB RKQBBRNN RKRBBQNN NRNBBKQR NRBQNBKR RNQBBKRN RBNNBKRQ RKRBBNQN NRNBBKQR RQKBBNRN RQBBNNKR RNBBQKRN BRKBNNRQ RKRBBNNQ NRNBBKQR RQKNBBRN RNBQNBKR RBNNKRBQ RKRBQNBN NRNBBKQR RQKNBBRN RNBQNBKR RNQKBRNB BRKQNNRB RKRBNQBN NRNBBKQR RQKNBBRN RBBQNNKR RNBKNRQB RKBBRNNQ RKR...