QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#710392#7179. Fischer's Chess Guessing Gameno_RED_no_DEADRE 136ms3720kbC++202.7kb2024-11-04 19:41:132024-11-04 19:41:14

Judging History

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

  • [2024-11-04 19:41:14]
  • 评测
  • 测评结果:RE
  • 用时:136ms
  • 内存:3720kb
  • [2024-11-04 19:41: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;

ll pp[N];
vector<string> v;
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;
        v.push_back(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;
}

// NX1: Định lý Phong: càng gần trung tâm x thì càng nhiều trường hợp 
// Lần thử 1: Đỉnh càng lớn thì càng tệ

void doTest(ll testID) {
    backtrack(1, 0, 0, 0, 0, 0); 

    while (true) {
        string s; ll num; cin >> s; if (s == "END") return; cin >> num;

        vector<string> cv = v; 
        for (int i = 1; ; i ++) {
            assert(i <= 6);
            string chs = cv[0];

            if (i != 1) {
                ll mx = 1e18;
                for (auto x: cv) {
                    // Reset
                    for (int j = 0; j <= 8; j ++) pp[j] = 0;
                    // Lập cái đồ thị
                    for (auto y: cv) pp[get(x, y)] ++;
                    // Tìm đỉnh của đồ thị
                    ll t = 0; for (int j = 0; j <= 8; j ++) t = max(t, pp[j]);
                    // Chọn đồ thị có đỉnh bé nhất
                    if (t < mx) mx = t, chs = x;
                }
            }

            cout << chs << endl; ll req; cin >> req; 
            if (req == 8) break;
            
            vector<string> nv;
            for (auto x: cv)
                if (get(x, chs) == req) 
                    nv.push_back(x);
            cv = nv;
        }
    }
}

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: 2ms
memory: 3644kb

input:

GAME 1
3
1
2
3
8
END

output:

RNNBBKRQ
BBRNNKRQ
RNQNBBKR
RBNKBRQN
RKRBBQNN

result:

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

Test #2:

score: 0
Accepted
time: 136ms
memory: 3720kb

input:

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

output:

RNNBBKRQ
BBRNNKRQ
RNQNBBKR
RBNKBRQN
RKRBBQNN
RNNBBKRQ
BBRNNKRQ
RNQNBBKR
RBNKBRQN
RKRBBNQN
RNNBBKRQ
RKNBBNQR
RNNKBBQR
RKNBRNBQ
RKRBBNNQ
RNNBBKRQ
RKBNQNRB
RNKRQNBB
RNBKQRNB
RKRBQNBN
RNNBBKRQ
RKBNQNRB
RBKNNRBQ
RBKRBNQN
RBBQNKNR
RKRBNQBN
RNNBBKRQ
BBRNNKRQ
RBNNQKBR
NRQNBKRB
RKRBNNBQ
RNNBBKRQ
RKBNQNRB
RBK...

result:

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

Test #3:

score: -100
Runtime Error

input:

GAME 1
3
0
3
5
3
8
GAME 2
4
6
4
5
8
GAME 3
4
8
GAME 4
2
3
3
2
2
2

output:

RNNBBKRQ
BBRNNKRQ
RNKRBQNB
RKNQBBNR
RKNRBBQN
RKQBBNNR
RNNBBKRQ
RKNBBNQR
RNKBBNQR
RKNBBRQN
RKNBBQNR
RNNBBKRQ
RKNBBNQR
RNNBBKRQ
RKBNQNRB
RKBBRQNN
RNBKQBNR
RNKNRQBB
RKRNBBQN

result: