QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#216862#7179. Fischer's Chess Guessing Gamecardinal_city#ML 19ms3768kbC++142.3kb2023-10-16 03:30:482024-01-17 03:30:55

Judging History

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

  • [2024-01-17 03:30:55]
  • 管理员手动重测该提交记录
  • 测评结果:ML
  • 用时:19ms
  • 内存:3768kb
  • [2023-10-16 03:30:48]
  • 提交

answer

#include <algorithm>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define smx(a, b) a = max(a, b);
#define smn(a, b) a = min(a, b);
#define pb push_back
//#define endl '\n'

const ll MOD = 1e9 + 7;
const ld EPS = 1e-9;

bool check(string x) {
  int b1 = -1;
  int b2 = -1;
  int r = 0;
  for (int i = 0; i < 9; i++) {
    if (x[i] == 'R')
      r++;
    if (x[i] == 'K') {
      if (r != 1)
        return false;
    }
    if (x[i] == 'B') {
      if (b1 == -1) {
        b1 = i % 2;
      } else {
        b2 = i % 2;
      }
    }
  }
  if (b1 == b2)
    return false;
  return true;
}

vector<string> poss;

int match(string s, string t) {
  int c = 0;
  for (int i = 0; i < 8; i++)
    if (s[i] == t[i])
      c++;
  return c;
}

void play(vector<pair<string, int>> curr, vector<string> &cposs) {
  string bests = "";
  int maxv = 1e9;
  for (auto s : cposs) {

    vi cnts(9);
    for (auto t : cposs) {
      cnts[match(s, t)]++;
    }

    // for (auto x : cnts)
    //   cout << x << " ";
    // cout << endl;

    if (*max_element(all(cnts)) < maxv) {
      maxv = *max_element(all(cnts));
      bests = s;
    }
  }
  cout << bests << endl;
  int res;
  cin >> res;

  if (res == 8)
    return;

  curr.pb({bests, res});
  vector<string> nposs;
  for (auto t : cposs) {
    bool good = true;
    for (auto s : curr) {
      if (match(s.first, t) != s.second)
        good = false;
    }
    if (good)
      nposs.pb(t);
  }
  // cout << nposs.size() << endl;

  play(curr, nposs);
}

int main() {
  // cin.tie(0)->sync_with_stdio(0);

  string x = "BBKNNQRR";
  set<string> pset;
  int cnt = 0;
  do {
    if (check(x)) {
      pset.insert(x);
    }
    cnt++;
  } while (next_permutation(all(x)));

  for (auto s : pset)
    poss.pb(s);
  // cout << pset.size() << endl;

  string game = "";
  for (int i = 0; i < 100; i++) {
    cin >> game;

    if (game == "END")
      return 0;
    int t;
    cin >> t;
    vector<string> cposs = poss;
    play({}, cposs);
  }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 19ms
memory: 3768kb

input:

GAME 1
1
2
2
1
2
8
END

output:

NRBBNKQR
BNRKQBNR
RNBQKRNB
BRNQKBRN
QNRNBKRB
RKRBBQNN

result:

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

Test #2:

score: -100
Memory Limit Exceeded

input:

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

output:

NRBBNKQR
BNRKQBNR
RNBQKRNB
BRNQKBRN
QNRNBKRB
RKRBBQNN
NRBBNKQR
RBBNKQNR
QRKNNRBB
NBNRBKRQ
BQNBRNKR
RKRBBNQN
NRBBNKQR
BNRKQBNR
RNBQKRNB
BRNQKBRN
RBKNBQNR
RKRBBNNQ
NRBBNKQR
BNRKQBNR
RNBQKRNB
BBNQRNKR
QBRKNRBN
RKRBQNBN
NRBBNKQR
RBBNKQNR
NBNQBRKR
BRKBRQNN
QRBKRNNB
RKRBNQBN
NRBBNKQR
RBBNKQNR
QRKNNRBB
NRK...

result: