QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#250290#7179. Fischer's Chess Guessing GametarjenAC ✓151ms93684kbC++202.5kb2023-11-13 01:52:442023-11-13 01:52:44

Judging History

你现在查看的是最新测评结果

  • [2023-11-13 01:52:44]
  • 评测
  • 测评结果:AC
  • 用时:151ms
  • 内存:93684kb
  • [2023-11-13 01:52:44]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int maxn=1e6+10;
vector<int>ve[maxn];
int dep[maxn];
string s[maxn],q[maxn];
vector<string> all;
void getlegal()
{
    vector<int> a(8);iota(a.begin(),a.end(),0);
    string s="RQKBBNRN";
    sort(s.begin(),s.end());
    do{
        string ss;
        for(int i=0;i<8;i++)ss.push_back(s[a[i]]);
        bool flag=true;
        int g=0,k;
        vector<int> v;
        for(int i=0;i<8;i++){
            if(ss[i]=='K')k=i;
            if(ss[i]=='R')v.push_back(i);
            if(ss[i]=='B')g+=i;
        }
        if(g%2==1&&k>v[0]&&k<v[1])all.push_back(ss);
    }while(next_permutation(a.begin(),a.end()));
    sort(all.begin(),all.end());
    all.resize(unique(all.begin(),all.end())-all.begin());
}
int f(string s1,string s2){
    int res=0;
    for(int i=0;i<8;i++)res+=s1[i]==s2[i];
    return res;
}
int tot=0;
int dfs(vector<string>&now,int d){
    if((int)now.size()==1){
        s[++tot]=now[0];
        return tot;
    }
    if(now.empty())return -1;
    assert(d<=5);
    int id=++tot;
    int mi=1e9;
    string tt;
    for(auto &it:all){
        vector<string> p[9];
        int g=0;
        for(auto &t:now){
            int z=f(it,t);
            p[z].push_back(t);
            g=max((int)p[z].size(),g);
        }
        if(g<mi){
            mi=g;tt=it;
        }
    }
    vector<string> p[9];
    for(auto &t:now){
        int z=f(tt,t);
        p[z].push_back(t);
    }
    q[id]=tt;
    for(int i=0;i<9;i++)ve[id].push_back(dfs(p[i],d+1));
    // cout<<"id="<<id<<"\n";
    // for(auto it:ve[id])cout<<it<<" ";;cout<<"\n";
    return id;
}
void init()
{
    getlegal();
    dfs(all,1);
}
struct gettime{
    clock_t star,ends;
    void begin(){
        star = clock();
    }
    void end(){
        ends = clock();
        cout <<"Running Time : "<<(double)(ends - star)/ CLOCKS_PER_SEC << endl;
    }
} tim;
int query(string s){
    cout<<s<<endl;
    int x;cin>>x;return x;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    tim.begin();
    init();
    string z;
    while(cin>>z){
        if(z=="END")break;
        int t;cin>>t;
        int now=1;
        bool flag=false;
        while(s[now].empty()){
            // cout<<"now="<<now<<"\n";
            int g=query(q[now]);
            if(g==8){
                flag=true;
                break;
            }
            now=ve[now][g];
            assert(now!=-1);
        }
        if(!flag)query(s[now]);
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 142ms
memory: 93684kb

input:

GAME 1
1
0
2
4
8
END

output:

NRBBNKQR
BRNNKBQR
NBRKNQBR
QBRKBRNN
RKRBBQNN

result:

ok (c) correct after 1 tests, max moves 5 (1 test case)

Test #2:

score: 0
Accepted
time: 140ms
memory: 91624kb

input:

GAME 1
1
0
2
4
8
GAME 2
2
3
3
1
1
8
GAME 3
1
0
1
2
8
GAME 4
1
0
2
2
1
8
GAME 5
2
3
4
2
8
GAME 6
2
2
4
0
0
8
GAME 7
0
2
3
2
0
8
GAME 8
1
3
3
0
8
GAME 9
0
3
3
0
8
GAME 10
0
3
3
1
8
GAME 11
0
5
1
0
8
GAME 12
1
2
2
1
0
8
GAME 13
1
1
5
1
8
GAME 14
0
4
4
3
8
GAME 15
1
2
1
2
1
8
GAME 16
1
0
3
1
0
8
GAME 17...

output:

NRBBNKQR
BRNNKBQR
NBRKNQBR
QBRKBRNN
RKRBBQNN
NRBBNKQR
RNBBQKRN
RQKBNNBR
BBRNNQKR
BBNNRKQR
RKRBBNQN
NRBBNKQR
BRNNKBQR
NBRKNQBR
BNRKQRNB
RKRBBNNQ
NRBBNKQR
BRNNKBQR
NBRKNQBR
QBRKBRNN
BBNNQRKR
RKRBQNBN
NRBBNKQR
RNBBQKRN
RQKBNNBR
QNRBBKNR
RKRBNQBN
NRBBNKQR
RNBBQKRN
QNRBKNBR
BBNNQRKR
BBNNRKQR
RKRBNNBQ
NRB...

result:

ok (c) correct after 96 tests, max moves 6 (96 test cases)

Test #3:

score: 0
Accepted
time: 141ms
memory: 91604kb

input:

GAME 1
2
2
3
1
2
8
GAME 2
2
2
2
5
2
8
GAME 3
3
1
4
2
8
GAME 4
3
1
3
1
1
8
GAME 5
2
3
5
2
8
GAME 6
3
1
3
0
2
8
GAME 7
1
3
5
1
8
GAME 8
1
3
3
4
8
GAME 9
2
1
3
2
3
8
GAME 10
2
1
0
0
4
8
GAME 11
2
1
1
3
2
8
GAME 12
1
4
3
4
8
GAME 13
0
2
2
3
8
GAME 14
1
1
2
2
2
8
GAME 15
0
1
0
1
8
GAME 16
0
2
2
1
8
GAME ...

output:

NRBBNKQR
RNBBQKRN
QNRBKNBR
BNNQRBKR
BBQNNRKR
RKQBBNNR
NRBBNKQR
RNBBQKRN
QNRBKNBR
RBNNBQKR
BBNNQRKR
RKNBBQNR
NRBBNKQR
RBBNQKRN
BQNBRNKR
BRKRNNQB
RKNBBNQR
NRBBNKQR
RBBNQKRN
BQNBRNKR
BBRNKNRQ
BBNNRKQR
RKQBNNBR
NRBBNKQR
RNBBQKRN
RQKBNNBR
BBNNRKQR
RKNBQNBR
NRBBNKQR
RBBNQKRN
BQNBRNKR
BBRNKNRQ
BBNQRKNR
RKN...

result:

ok (c) correct after 96 tests, max moves 6 (96 test cases)

Test #4:

score: 0
Accepted
time: 137ms
memory: 91820kb

input:

GAME 1
1
2
1
4
0
8
GAME 2
3
1
0
1
8
GAME 3
2
0
3
0
8
GAME 4
1
1
0
1
0
8
GAME 5
2
0
4
0
0
8
GAME 6
3
0
1
0
8
GAME 7
2
1
1
0
8
GAME 8
2
2
1
1
0
8
GAME 9
3
0
0
6
8
GAME 10
2
0
4
1
0
8
GAME 11
2
1
3
1
1
8
GAME 12
3
0
0
4
8
GAME 13
2
2
1
1
2
8
GAME 14
3
1
4
5
8
GAME 15
2
1
1
3
1
8
GAME 16
1
3
0
4
8
GAME ...

output:

NRBBNKQR
BRNNKBQR
BNRBKRQN
BRKQNBNR
BBNNQRKR
QRKRBBNN
NRBBNKQR
RBBNQKRN
BQNBRNKR
BNQRKRNB
NRKRBBQN
NRBBNKQR
RNBBQKRN
BRKQNRNB
BBQNNRKR
NRKRBBNQ
NRBBNKQR
BRNNKBQR
RKQNRBBN
BBRKNNRQ
BBNNQRKR
QRKRBNNB
NRBBNKQR
RNBBQKRN
BRKQNRNB
BBNQRNKR
BBNNQRKR
NRKRBQNB
NRBBNKQR
RBBNQKRN
BNRBQNKR
BBNQNRKR
NRKRBNQB
NRB...

result:

ok (c) correct after 96 tests, max moves 6 (96 test cases)

Test #5:

score: 0
Accepted
time: 132ms
memory: 91604kb

input:

GAME 1
0
4
5
2
8
GAME 2
0
3
0
2
8
GAME 3
0
4
5
3
8
GAME 4
0
5
1
3
8
GAME 5
0
4
4
2
8
GAME 6
0
6
4
1
8
GAME 7
1
0
2
5
8
GAME 8
3
4
1
3
8
GAME 9
2
2
0
0
2
8
GAME 10
0
1
0
2
8
GAME 11
1
2
3
1
3
8
GAME 12
0
2
4
0
8
GAME 13
1
0
4
2
1
8
GAME 14
0
3
1
1
8
GAME 15
1
1
2
1
3
8
GAME 16
2
2
0
1
1
8
GAME 17
1
0...

output:

NRBBNKQR
RKNNRQBB
QNRKRBBN
BBNNRKRQ
RQNKRBBN
NRBBNKQR
RKNNRQBB
BQRNKRNB
NRKQRNBB
RNQKRBBN
NRBBNKQR
RKNNRQBB
QNRKRBBN
BBNNRKRQ
RNNKRBBQ
NRBBNKQR
RKNNRQBB
BBNRKQRN
BBNQRNKR
RQNKRNBB
NRBBNKQR
RKNNRQBB
QNRKRBBN
BBRKQNRN
RNQKRNBB
NRBBNKQR
RKNNRQBB
BNNRKQRB
BBNNQRKR
RNNKRQBB
NRBBNKQR
BRNNKBQR
NBRKNQBR
QBR...

result:

ok (c) correct after 96 tests, max moves 6 (96 test cases)

Test #6:

score: 0
Accepted
time: 144ms
memory: 91604kb

input:

GAME 1
3
3
1
2
0
8
GAME 2
3
4
0
0
8
GAME 3
4
3
1
0
8
GAME 4
3
2
0
3
8
GAME 5
3
3
0
2
1
8
GAME 6
4
2
0
1
8
GAME 7
1
3
1
1
1
8
GAME 8
2
2
0
4
0
8
GAME 9
2
1
5
1
8
GAME 10
1
2
0
2
1
8
GAME 11
2
1
5
0
8
GAME 12
2
1
6
2
8
GAME 13
3
0
2
3
2
8
GAME 14
2
1
3
5
4
8
GAME 15
4
2
4
4
8
GAME 16
4
1
4
5
8
GAME 17...

output:

NRBBNKQR
RBBNQKRN
BBQRNKNR
BBNRQKRN
BBNNRKQR
QRBKNBRN
NRBBNKQR
RBBNQKRN
BBNNRQKR
BBNQRKNR
NRBKQBRN
NRBBNKQR
BNRBNKRQ
BNNRQBKR
BNRBQKNR
NRBKNBRQ
NRBBNKQR
RBBNQKRN
BBNQRKNR
BQRKNRNB
QRBKNNRB
NRBBNKQR
RBBNQKRN
BBQRNKNR
BBRNKNRQ
BBNNQRKR
NRBKQNRB
NRBBNKQR
BNRBNKRQ
BBNNRKQR
BBNQRKRN
NRBKNQRB
NRBBNKQR
BRN...

result:

ok (c) correct after 96 tests, max moves 6 (96 test cases)

Test #7:

score: 0
Accepted
time: 151ms
memory: 91624kb

input:

GAME 1
1
1
2
2
1
8
GAME 2
2
3
1
1
3
8
GAME 3
1
2
2
3
2
8
GAME 4
0
3
3
3
8
GAME 5
0
3
2
1
8
GAME 6
0
4
1
4
8
GAME 7
2
4
2
0
8
GAME 8
3
3
0
1
1
8
GAME 9
2
4
3
2
8
GAME 10
1
2
2
1
1
8
GAME 11
1
1
1
8
GAME 12
2
3
1
0
2
8
GAME 13
1
2
4
3
8
GAME 14
1
1
4
1
1
8
GAME 15
1
2
4
4
8
GAME 16
0
5
2
3
8
GAME 17
0...

output:

NRBBNKQR
BRNNKBQR
RKQNRBBN
BBRNQKRN
BBNNRKQR
RBBQKRNN
NRBBNKQR
RNBBQKRN
RQKBNNBR
BBNRNKRQ
BBNNQRKR
RBBNKRQN
NRBBNKQR
BRNNKBQR
BNRBKRQN
BBNNRKRQ
BBNQNRKR
RBBNKRNQ
NRBBNKQR
RKNNRQBB
BQRNKRNB
NQNRKRBB
RBQNKRBN
NRBBNKQR
RKNNRQBB
BQRNKRNB
QRNKBNRB
RBNQKRBN
NRBBNKQR
RKNNRQBB
QNRKRBBN
BBNNQRKR
RBNNKRBQ
NRB...

result:

ok (c) correct after 96 tests, max moves 6 (96 test cases)

Test #8:

score: 0
Accepted
time: 139ms
memory: 91836kb

input:

GAME 1
3
0
3
3
8
GAME 2
4
1
2
2
8
GAME 3
4
1
2
4
8
GAME 4
2
0
1
2
3
8
GAME 5
3
1
1
2
2
8
GAME 6
3
0
1
3
3
8
GAME 7
0
0
6
3
8
GAME 8
1
4
1
5
8
GAME 9
0
1
4
4
8
GAME 10
1
2
6
2
8
GAME 11
2
3
1
1
2
8
GAME 12
1
2
6
1
8
GAME 13
0
2
0
3
8
GAME 14
0
1
5
2
8
GAME 15
1
4
2
3
8
GAME 16
0
2
0
2
8
GAME 17
1
1
2...

output:

NRBBNKQR
RBBNQKRN
BNRBQNKR
BQNBNRKR
QRNBKNBR
NRBBNKQR
BNRBNKRQ
NQBRNBKR
BBNRKQNR
NRQBKNBR
NRBBNKQR
BNRBNKRQ
NQBRNBKR
BBNRKQNR
NRNBKQBR
NRBBNKQR
RNBBQKRN
BRKQNRNB
BBRQKNNR
BBNNQRKR
QRNNKBBR
NRBBNKQR
RBBNQKRN
BQNBRNKR
BBRNNQKR
BBNNQRKR
NRQNKBBR
NRBBNKQR
RBBNQKRN
BNRBQNKR
BBNQNRKR
BBNQRKNR
NRNQKBBR
NRB...

result:

ok (c) correct after 96 tests, max moves 6 (96 test cases)

Test #9:

score: 0
Accepted
time: 135ms
memory: 93544kb

input:

GAME 1
2
1
0
3
2
8
GAME 2
3
2
3
2
8
GAME 3
4
0
1
3
8
GAME 4
1
3
3
3
3
8
GAME 5
2
0
0
2
2
8
GAME 6
2
0
0
2
3
8
GAME 7
2
2
4
1
1
8
GAME 8
3
1
2
3
1
8
GAME 9
4
1
5
1
8
GAME 10
1
4
4
2
8
GAME 11
2
0
0
4
2
8
GAME 12
2
1
1
1
2
8
GAME 13
3
6
1
2
8
GAME 14
2
6
3
8
GAME 15
3
6
2
3
8
GAME 16
1
1
4
1
2
8
GAME ...

output:

NRBBNKQR
RNBBQKRN
NRNKBRQB
BBRKRNNQ
BBNNQRKR
QBBRKNNR
NRBBNKQR
RBBNQKRN
BBNQRKNR
BBNRQKRN
NBBRKQNR
NRBBNKQR
BNRBNKRQ
BRNKQBNR
BBNNRKQR
NBBRKNQR
NRBBNKQR
BRNNKBQR
RBQNBNKR
BBNQRKNR
BBNNQRKR
QBNRKNBR
NRBBNKQR
RNBBQKRN
BRKQNRNB
BQRNKBNR
BBNNQRKR
NBQRKNBR
NRBBNKQR
RNBBQKRN
BRKQNRNB
BQRNKBNR
BBNNQRKR
NBN...

result:

ok (c) correct after 96 tests, max moves 6 (96 test cases)

Test #10:

score: 0
Accepted
time: 143ms
memory: 91616kb

input:

GAME 1
3
2
6
4
8
GAME 2
2
2
2
3
5
8
GAME 3
4
4
2
4
8
GAME 4
4
5
2
8
GAME 5
3
2
4
4
8
GAME 6
5
5
2
8
GAME 7
2
1
1
4
3
8
GAME 8
3
2
5
2
8
GAME 9
4
2
5
8
GAME 10
3
3
4
3
3
8
GAME 11
4
3
1
3
8
GAME 12
3
4
3
2
8
GAME 13
3
1
2
2
2
8
GAME 14
4
3
1
5
8
GAME 15
5
3
2
1
8
GAME 16
4
5
1
8
GAME 17
5
5
4
8
GAME ...

output:

NRBBNKQR
RBBNQKRN
BBNQRKNR
BBNNRKQR
BBRQNKNR
NRBBNKQR
RNBBQKRN
QNRBKNBR
RBNNBQKR
BBNNQRKR
BBRNQKNR
NRBBNKQR
BNRBNKRQ
BBNRKNRQ
BBNNQRKR
BBRNNKQR
NRBBNKQR
BNRBNKRQ
BBNNRKRQ
BQRBNKNR
NRBBNKQR
RBBNQKRN
BBNQRKNR
BRNBQKRN
BNRBQKNR
NRBBNKQR
BQRBNNKR
NQBBRNKR
BNRBNKQR
NRBBNKQR
RNBBQKRN
NRNKBRQB
BBNQRKNR
BBN...

result:

ok (c) correct after 96 tests, max moves 6 (96 test cases)

Test #11:

score: 0
Accepted
time: 140ms
memory: 91616kb

input:

GAME 1
2
2
3
3
3
8
GAME 2
2
3
4
4
8
GAME 3
2
3
3
3
3
8
GAME 4
1
4
4
3
8
GAME 5
1
3
6
2
8
GAME 6
1
3
4
4
2
8
GAME 7
4
3
3
6
8
GAME 8
3
1
6
5
8
GAME 9
4
3
4
3
8
GAME 10
3
1
3
2
4
8
GAME 11
3
0
3
5
8
GAME 12
2
1
2
5
6
8
GAME 13
5
5
5
8
GAME 14
5
4
0
8
GAME 15
6
1
1
8
GAME 16
4
1
5
3
8
GAME 17
5
3
2
2
8...

output:

NRBBNKQR
RNBBQKRN
QNRBKNBR
BNNQRBKR
BBNNQRKR
RQNBBNKR
NRBBNKQR
RNBBQKRN
RQKBNNBR
QNRBBKNR
RNQBBNKR
NRBBNKQR
RNBBQKRN
RQKBNNBR
BBRNNQKR
BBNNQRKR
RNNBBQKR
NRBBNKQR
BRNNKBQR
QNBNRBKR
BBNQNRKR
RQNNBBKR
NRBBNKQR
BRNNKBQR
RBQNBNKR
BBNNRKQR
RNQNBBKR
NRBBNKQR
BRNNKBQR
RBQNBNKR
BBNQNRKR
BBNNRKQR
RNNQBBKR
NRB...

result:

ok (c) correct after 96 tests, max moves 6 (96 test cases)

Extra Test:

score: 0
Extra Test Passed