QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#641519#7179. Fischer's Chess Guessing GamePedro_SimTL 276ms3832kbC++202.5kb2024-10-14 20:54:062024-10-14 20:54:07

Judging History

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

  • [2024-10-14 20:54:07]
  • 评测
  • 测评结果:TL
  • 用时:276ms
  • 内存:3832kb
  • [2024-10-14 20:54:06]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rp(i,a,b)        for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()


vector<string> resp;

bool veri(string &t) {
    int te = -1;
    rp(i, 0, 8){
        if(te >= 0 && t[i] == 'B' && (i%2) == (te%2)) return false;
        else if(t[i] == 'B') te = i;
    }
    rp(i, 0, 8){
        if(t[i] == 'K'){
            bool flag1 = true, flag2 = true;
            rp(j, 0, i) if(t[j] == 'R') flag1 = false;
            rp(j, i, 8) if(t[j] == 'R') flag2 = false;
            if(flag1 || flag2) return false;
            break;
        }
    }
    return true;
}

void solvetask() {
    int n;
    cin >> n;
    
    //for(auto original: resp){
        vector<string> currentState = resp; 
        string best;
    for(int turn = 0; turn < 7; turn++) {
        // if(turn == 6) {
        //     cout << original << " " << currentState.size() << "\n";
        //     break;
        // }

        int mx = 1e9;
        string chute;
        for (auto &comp : currentState) {
            vector<int> bins(9, 0); 
                
            for (auto &candidate : currentState) {
                int matches = 0;
                rp(k, 0, 8)  if (comp[k] == candidate[k]) matches++;
                bins[matches]++;
            }

            int mn = 0;
            for(auto i: bins) mn += i*i;
            if (mn < mx) {
                mx = mn;
                chute = comp;
            }
        }

       // if(turn == 0) chute = "RBBNNQKR";

       // if(turn == 5) chute = currentState[rand()%(currentState.size())];
        

        cout << chute << endl;
        fflush(stdout);
        int iguais=0;
        cin >> iguais;
       // rp(k, 0, 8) if (chute[k] == original[k]) iguais++;
        if (iguais == 8) break;

        vector<string> newState;
        for (auto &comp : currentState) {
            int matches = 0;
            rp(k, 0, 8) if (comp[k] == chute[k]) matches++;
            if (matches == iguais) newState.push_back(comp);
        }
        currentState = newState;
    }
    //}
}

void pre_cal() {
    string temp = "BBQKNNRR";
    sort(temp.begin(), temp.end());
    while(next_permutation(temp.begin(), temp.end())) if(veri(temp)) resp.push_back(temp);
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    string t;
    pre_cal();

    while (true) {
        cin >> t;
        if (t == "END") return 0; 
        solvetask();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3832kb

input:

GAME 1
2
2
1
4
8
END

output:

NRBBNQKR
RBBNQKNR
RQNKNBBR
RKBBRNQN
RKRBBQNN

result:

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

Test #2:

score: 0
Accepted
time: 276ms
memory: 3576kb

input:

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

output:

NRBBNQKR
RBBNQKNR
RQNKNBBR
RKBBRNQN
RKRBBQNN
NRBBNQKR
RKNNQBBR
RNBKQNRB
RBBNKRQN
NBRKQRBN
RKRBBNQN
NRBBNQKR
RKNNQBBR
RNBKQNRB
RBBNKRQN
QRKNRNBB
RKRBBNNQ
NRBBNQKR
RKNNQBBR
RKBNQNRB
RKBNRBNQ
RKRBQNBN
NRBBNQKR
RNQBBNKR
RBBQNKNR
BQNRNBKR
RKRBNQBN
NRBBNQKR
RBBNQKNR
BRKQNRNB
QNRKNBBR
BNRBKNQR
RKRBNNBQ
NRB...

result:

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

Test #3:

score: -100
Time Limit Exceeded

input:

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

output:

NRBBNQKR
RBBNQKNR
BBNRQNKR
RQKBBNNR
RKQBBNNR
NRBBNQKR
RNQBBNKR
RKBBQNNR
RBBNQNKR
RKNBBQNR
NRBBNQKR
RBBNQKNR
RQNKNBBR
RKBRNBQN
RKNBBNQR
NRBBNQKR
RNQBBNKR
NNQRBBKR
RKQBNNBR
NRBBNQKR
RBBNQKNR
BBNRQNKR
NBNRBKQR
BRNKQBNR
RKNBQNBR
NRBBNQKR
RNNBBQKR
NQNBBRKR
RKNBNQBR
NRBBNQKR
RKNNQBBR
RKQNBBNR
NRBBNQKR
RKN...

result: