QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#647213#7179. Fischer's Chess Guessing Gameno_RED_no_DEADRE 177ms4020kbC++203.3kb2024-10-17 12:45:132024-10-17 12:45:15

Judging History

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

  • [2024-10-17 12:45:15]
  • 评测
  • 测评结果:RE
  • 用时:177ms
  • 内存:4020kb
  • [2024-10-17 12:45:13]
  • 提交

answer

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

const ll N = 1e6 + 1;
const ll M = 1e9 + 7;
const ll B = 8;

vector<string> v;
set<string> s;
string cur;

void backtrack(ll pos, ll r, ll n, ll b, ll k, ll q) {
    if (pos > B) {
        ll r1 = 1e18, r2 = -1e18, b1 = 1e18, b2 = -1e18, k1 = -1e18;
        for (ll i = 0; i < cur.size(); i ++) {
            if (cur[i] == 'R') r1 = min(r1, i), r2 = max(r2, i);
            if (cur[i] == 'B') b1 = min(b1, i), b2 = max(b2, i);
            if (cur[i] == 'K') k1 = max(k1, i);
        }
        if (b1 % 2 == b2 % 2) return;
        if (r1 > k1 || r2 < k1) return;
        s.insert(cur);
        return;
    }
    if (r < 2) cur += 'R', backtrack(pos + 1, r + 1, n, b, k, q), cur.pop_back();
    if (n < 2) cur += 'N', backtrack(pos + 1, r, n + 1, b, k, q), cur.pop_back();
    if (b < 2) cur += 'B', backtrack(pos + 1, r, n, b + 1, k, q), cur.pop_back();
    if (k < 1) cur += 'K', backtrack(pos + 1, r, n, b, k + 1, q), cur.pop_back();
    if (q < 1) cur += 'Q', backtrack(pos + 1, r, n, b, k, q + 1), cur.pop_back();
}

ll get(string &a, string &b) {
    ll res = 0; 
    for (int i = 0; i < a.size(); i ++)
        if (a[i] == b[i]) res ++;
    return res;
}

mt19937_64 rng(static_cast<ll>(std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count()));

ll rand(ll l, ll r) {
    return uniform_int_distribution<ll>(l, r)(rng);
}

map<string, ll> m;

void doTest(ll testID) {
    backtrack(1, 0, 0, 0, 0, 0);
    for (auto x: s) v.push_back(x);

    ll test = 0;
    while (true) {
        string s; ll num; cin >> s; if (s == "END") return; cin >> num;
        m.clear();
        // /*#TEST*/ string real = v[rand(0, v.size() - 1)]; 
        // cout << "Real: " << real << endl;

        vector<string> cv = v; 
        for (int i = 1;; i ++) {
            // /*#TEST*/ if (i == 7) {
                // cout << real << endl;
            // }
            assert(i <= 6);
            
            string chs; array<ll, 9> cur = {(ll)1e18, 0, 0, 0, 0, 0, 0, 0, 0};
            if (i == 1) chs = "RKRBBNNQ";
            else {
                for (auto x: cv) {
                    if (m.count(x)) continue; map<ll, ll> pp;
                    array<ll, 9> tmp = {0, 0, 0, 0, 0, 0, 0, 0, 0}; for (auto y: cv) pp[get(x, y)] ++;
                    ll j = 0; for (auto [x, y]: pp) tmp[j] = y, j ++;
                    sort(tmp.begin(), tmp.end(), greater<ll>());
                    if (tmp < cur) cur = tmp, chs = x;
                }
            }
            cout << chs << endl;
            m[chs] ++;
            
            ll req; 
            cin >> req; 
            // /*#TEST*/ req = get(real, chs);
            if (req == 8) break;
            
            vector<string> nv;
            for (auto x: cv)
                if (get(x, chs) == req) 
                    nv.push_back(x);
            cv = nv;

            // cout << cv.size() << endl;
        }
        // /*#TEST*/ test ++; cout << "Accept test: " << test << endl;
    }
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);

    int test = 1; 
    // cin >> test;
    for (int _ = 1; _ <= test; _ ++) doTest(_);
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3932kb

input:

GAME 1
6
4
8
END

output:

RKRBBNNQ
RKNBBNRQ
RKRBBQNN

result:

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

Test #2:

score: 0
Accepted
time: 71ms
memory: 3992kb

input:

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

output:

RKRBBNNQ
RKNBBNRQ
RKRBBQNN
RKRBBNNQ
RKNBBNRQ
RKBBRNNQ
RKRBBNQN
RKRBBNNQ
RKRBBNNQ
RKRBQNBN
RKRBBNNQ
RKNQBRNB
RKQBRNBN
RKBBQNRN
RKRBNQBN
RKRBBNNQ
RKNBBNRQ
RKBBRNNQ
RKQBBNNR
RKRBNNBQ
RKRBBNNQ
RKRBQNBN
RKRQBBNN
RKRBBNNQ
RKNQBRNB
RKBBNQNR
NRKBBRNQ
RKRNBBQN
RKRBBNNQ
RKNBBNRQ
RKRBBQNN
RKRNBBNQ
RKRBBNNQ
RKN...

result:

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

Test #3:

score: 0
Accepted
time: 148ms
memory: 3796kb

input:

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

output:

RKRBBNNQ
RKNBBNRQ
RKBBRNNQ
RKQBBNNR
RKRBBNNQ
RKRBQNBN
RKNBBQNR
RKRBBNNQ
RKRBQNBN
RKRQBBNN
RKNBBNQR
RKRBBNNQ
RKNQBRNB
RKQBRNBN
RKBBRNQN
RKQBNNBR
RKRBBNNQ
RKNQBRNB
RKBBNQNR
RNQBBKNR
RKNBQNBR
RKRBBNNQ
RKQNBBRN
RKNQRNBB
RBKNRNBQ
RKBRNNQB
RKNBNQBR
RKRBBNNQ
RKNQBRNB
RBKQBNNR
RKQNBBNR
RKRBBNNQ
RKNQBRNB
RKN...

result:

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

Test #4:

score: 0
Accepted
time: 177ms
memory: 4020kb

input:

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

output:

RKRBBNNQ
BRNBKQNR
RBBNKNQR
BQRKNRNB
NRNKBBRQ
QRKRBBNN
RKRBBNNQ
RNQKNBBR
BRKBNQRN
BNRNKQRB
NRKRBBQN
RKRBBNNQ
RKQNBBRN
RKNQRNBB
QBRNBKNR
NRKRBBNQ
RKRBBNNQ
RKQNBBRN
NNRBBKQR
BBRKNNRQ
QRKRBNNB
RKRBBNNQ
BRNBKQNR
BRKRQNNB
NRKRBQNB
RKRBBNNQ
BRNBKQNR
NBRNBKQR
NRKNBBRQ
NRKRBNQB
RKRBBNNQ
BBNRQKRN
BRNKNBQR
QNN...

result:

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

Test #5:

score: -100
Runtime Error

input:

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

output:

RKRBBNNQ
RNQKNBBR
RNNKRQBB
RNBKNQRB
RQNKRBBN
RKRBBNNQ
RNQKNBBR
RQNKNBBR
RNQKNRBB
RNQKRBBN
RKRBBNNQ
BRNBKQNR
NBRNBKQR
RKNQRBBN
RKNQNRBB
RNNKRBBQ
RKRBBNNQ
BRNBKQNR
NBRNBKQR
RKNQRBBN
RQBKRBNN
RQNKRNBB
RKRBBNNQ
BRNBKQNR
RQKNRNBB
NQRKRNBB
RNQKRNBB
RKRBBNNQ
RNQKNBBR
RNNKRQBB
RKRBBNNQ
BRNBKQNR
NBRNBKQR
BNR...

result: