QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#708937#7179. Fischer's Chess Guessing GametanphRE 1ms3688kbC++202.7kb2024-11-04 09:52:012024-11-04 09:52:03

Judging History

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

  • [2024-11-04 09:52:03]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3688kb
  • [2024-11-04 09:52:01]
  • 提交

answer

#include <bits/stdc++.h>
#include "random"
using namespace std;

using i16 = short int;
using i32 = int32_t;
using i64 = int64_t;
using ui16 = unsigned short int;
using ui32 = uint32_t;
using ui64 = uint64_t;

template<class T>
using v = vector<T>;

#define all(a) (a).begin(), (a).end()
#define open(x) freopen(#x ".inp", "r", stdin), freopen(#x ".out", "w", stdout)

template<class X, class Y> bool mimi(X &x, const Y &y) {if(x > y) {x = y; return 1;} return 0;}
template<class X, class Y> bool mama(X &x, const Y &y) {if(x < y) {x = y; return 1;} return 0;}

const i32 N = 2 * 1e5;
const i32 M = 1e9 + 7;
const i32 inf = 1e9 + 9;
const i64 infll = 1e18 + 18;

// mt19937_64 rng(static_cast<i32>(chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count()));
// i32 rand(i32 l, i32 r) {
//     return uniform_int_distribution<i32>(l, r)(rng);
// }

string d = "RRNNBBKQ";
bool check(string &s) {
    v<i32> pos(5, -1);
    for(i32 i = 0; i < 8; i ++) {
        if(s[i] == 'R') if(pos[0] == -1) pos[0] = i;
        else pos[1] = i;
        if(s[i] == 'B') if(pos[2] == -1) pos[2] = i;
        else pos[3] = i;
        if(s[i] == 'K') pos[4] = i;
    }
    if(pos[0] > pos[4] || pos[1] < pos[4]) return false;
    if((pos[2] & 1) == (pos[3] & 1)) return false;
    return true;
}
v<string> states; 
i32 n = 960;
void sad(i32 testID) {
    string s; i32 huybeos;
    while(true) {
        cin >> s;
        if(s == "END") break;
        cin >> huybeos;
        i32 c = 0, idx = 0;
        while(c != 8) {
            if(states.empty()) throw std::runtime_error("No solution");
            idx = (idx + 1) % states.size();
            string temp = states[idx];
            cout << temp << endl;
            cin >> c;
            if(c == 8) break;
            for(i32 j = states.size() - 1; j >= 0; j --) {
                i32 cnt = 0;
                for(i32 k = 0; k < 8; k ++) 
                    if(states[j][k] == temp[k]) cnt ++;
                // if(states[j] == "RKRBBQNN") cout << "Match: " << cnt << endl;
                if(cnt != c) states.erase(states.begin() + j);
            }
            // cout << "Remaining: " << states.size() << endl;
        }
    }
}

i32 main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    sort(all(d));
    do {
        if(check(d)) states.push_back(d);
    } while(next_permutation(all(d)));
    states.resize(distance(states.begin(), unique(states.begin(), states.end())));

    i32 t = 1;
    // cin >> t;
    for(i32 testID = 1; testID <= t; testID++) {
        // cout << "Case #" << testID << ":\n";
        sad(testID);
    }
    return 0;
}

详细

Test #1:

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

input:

GAME 1
0
0
5
8
END

output:

BBNNRKQR
NNQRKRBB
RKBBNQRN
RKRBBQNN

result:

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

Test #2:

score: -100
Runtime Error

input:

GAME 1
0
0
5
8
GAME 2
2
6

output:

BBNNRKQR
NNQRKRBB
RKBBNQRN
RKRBBQNN
RQBKNBRN
RKRBBQNN

result: