QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#700733#9537. Chinese Chessucup-team008#RE 3ms4088kbC++179.5kb2024-11-02 13:20:492024-11-02 13:21:12

Judging History

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

  • [2024-11-02 13:21:12]
  • 评测
  • 测评结果:RE
  • 用时:3ms
  • 内存:4088kb
  • [2024-11-02 13:20:49]
  • 提交

answer

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;

// BEGIN NO SAD
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
typedef vector<int> vi;
#define f first
#define s second
#define derr if(0) cerr
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << flush;
// END NO SAD

template<class Fun>
class y_combinator_result {
  Fun fun_;
public:
  template<class T>
  explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}

  template<class ...Args>
  decltype(auto) operator()(Args &&...args) {
    return fun_(std::ref(*this), std::forward<Args>(args)...);
  }
};

template<class Fun>
decltype(auto) y_combinator(Fun &&fun) {
  return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}

template<class T>
bool updmin(T& a, T b) {
  if(b < a) {
    a = b;
    return true;
  }
  return false;
}
template<class T>
bool updmax(T& a, T b) {
  if(b > a) {
    a = b;
    return true;
  }
  return false;
}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<ll>> matrix;

const string ALPHA = "JSCMXB";
int dp[6][10][9][10][9];
const int R = 10;
const int C = 9;
bool isvalidloc(int x, int y) {
  return x >= 0 && x < R && y >= 0 && y < C;
}
void init() {
  memset(dp, 1, sizeof(dp));
  // 0, king moves
  {
    int dx[4]{-1,0,1,0};
    int dy[4]{0,1,0,-1};
    for(int i = 0; i < R; i++) for(int j = 0; j < C; j++) {
      dp[0][i][j][i][j] = 0;
      queue<array<int, 2>> q;
      q.push({i, j});
      while(sz(q)) {
        auto [x, y] = q.front(); q.pop();
        for(int k = 0; k < 4; k++) {
          int nx = x + dx[k];
          int ny = y + dy[k];
          if(isvalidloc(nx, ny) && dp[0][i][j][nx][ny] > dp[0][i][j][x][y] + 1) {
            dp[0][i][j][nx][ny] = dp[0][i][j][x][y] + 1;
            q.push({nx, ny});
          }
        }
        if(dp[0][i][j][x][y] == 0) dp[0][i][j][x][y] = 1e9;
      }
    }
  }
  // 1, mandarin moves
  {
    int dx[4]{-1,-1,1,1};
    int dy[4]{-1,1,-1,1};
    for(int i = 0; i < R; i++) for(int j = 0; j < C; j++) {
      dp[1][i][j][i][j] = 0;
      queue<array<int, 2>> q;
      q.push({i, j});
      while(sz(q)) {
        auto [x, y] = q.front(); q.pop();
        for(int k = 0; k < 4; k++) {
          int nx = x + dx[k];
          int ny = y + dy[k];
          if(isvalidloc(nx, ny) && dp[1][i][j][nx][ny] > dp[1][i][j][x][y] + 1) {
            dp[1][i][j][nx][ny] = dp[1][i][j][x][y] + 1;
            q.push({nx, ny});
          }
        }
        if(dp[1][i][j][x][y] == 0) dp[1][i][j][x][y] = 1e9;
      }
    }
  }
  // 2, rook moves
  {
    for(int i = 0; i < R; i++) for(int j = 0; j < C; j++) {
      dp[2][i][j][i][j] = 0;
      queue<array<int, 2>> q;
      q.push({i, j});
      while(sz(q)) {
        auto [x, y] = q.front(); q.pop();
        for(int nx = 0; nx < R; nx++) {
          int ny = y;
          if(isvalidloc(nx, ny) && dp[2][i][j][nx][ny] > dp[2][i][j][x][y] + 1) {
            dp[2][i][j][nx][ny] = dp[2][i][j][x][y] + 1;
            q.push({nx, ny});
          }
        }
        for(int ny = 0; ny < C; ny++) {
          int nx = x;
          if(isvalidloc(nx, ny) && dp[2][i][j][nx][ny] > dp[2][i][j][x][y] + 1) {
            dp[2][i][j][nx][ny] = dp[2][i][j][x][y] + 1;
            q.push({nx, ny});
          }
        }
        if(dp[2][i][j][x][y] == 0) dp[2][i][j][x][y] = 1e9;
      }
    }
  }
  // 3, knight moves
  {
    int dx[8]{-2,-1,1,2,2,1,-1,-2};
    int dy[8]{1,2,2,1,-1,-2,-2,-1};
    for(int i = 0; i < R; i++) for(int j = 0; j < C; j++) {
      dp[3][i][j][i][j] = 0;
      queue<array<int, 2>> q;
      q.push({i, j});
      while(sz(q)) {
        auto [x, y] = q.front(); q.pop();
        for(int k = 0; k < 8; k++) {
          int nx = x + dx[k];
          int ny = y + dy[k];
          if(isvalidloc(nx, ny) && dp[3][i][j][nx][ny] > dp[3][i][j][x][y] + 1) {
            dp[3][i][j][nx][ny] = dp[3][i][j][x][y] + 1;
            q.push({nx, ny});
          }
        }
        if(dp[3][i][j][x][y] == 0) dp[3][i][j][x][y] = 1e9;
      }
    }
  }
  // 4, bishop moves
  {
    int dx[4]{-2,-2,2,2};
    int dy[4]{-2,2,-2,2};
    for(int i = 0; i < R; i++) for(int j = 0; j < C; j++) {
      dp[4][i][j][i][j] = 0;
      queue<array<int, 2>> q;
      q.push({i, j});
      while(sz(q)) {
        auto [x, y] = q.front(); q.pop();
        for(int k = 0; k < 4; k++) {
          int nx = x + dx[k];
          int ny = y + dy[k];
          if(isvalidloc(nx, ny) && dp[4][i][j][nx][ny] > dp[4][i][j][x][y] + 1) {
            dp[4][i][j][nx][ny] = dp[4][i][j][x][y] + 1;
            q.push({nx, ny});
          }
        }
        if(dp[4][i][j][x][y] == 0) dp[4][i][j][x][y] = 1e9;
      }
    }
  }
  // 5, pawn moves
  {
    for(int i = 0; i < R; i++) for(int j = 0; j < C; j++) {
      dp[5][i][j][i][j] = 0;
      queue<array<int, 2>> q;
      q.push({i, j});
      while(sz(q)) {
        auto [x, y] = q.front(); q.pop();
        if(x <= 4) {
          int nx = x+1;
          int ny = y;
          if(isvalidloc(nx, ny) && dp[5][i][j][nx][ny] > dp[5][i][j][x][y] + 1) {
            dp[5][i][j][nx][ny] = dp[5][i][j][x][y] + 1;
            q.push({nx, ny});
          }
        }
        else {
          int dx[3]{1,0,0};
          int dy[3]{0,-1,1};
          for(int k = 0; k < 3; k++) {
            int nx = x + dx[k];
            int ny = y + dy[k];
            if(isvalidloc(nx, ny) && dp[5][i][j][nx][ny] > dp[5][i][j][x][y] + 1) {
              dp[5][i][j][nx][ny] = dp[5][i][j][x][y] + 1;
              q.push({nx, ny});
            }
          }
        }
        if(dp[5][i][j][x][y] == 0) dp[5][i][j][x][y] = 1e9;
      }
    }
  }
}

map<vector<array<int, 3>>, int> medp;
map<vector<array<int, 3>>, array<int, 2>> meopt;
int me(vector<array<int, 3>>& v, int depth) {
  assert(sz(v));
  if(medp.count(v)) return medp[v];
  vector<bool> seen(6);
  for(auto [_, a, b]: v) seen[_] = true;
  int amtseen = 0;
  for(int i = 0; i < 6; i++) amtseen += seen[i];
  assert(amtseen > 0);
  if(amtseen == 1) return medp[v] = 0;
  if(depth == 3) return 100;
  int ret = 1e9;
  for(int i = 0; ret > 1 && i < R; i++) for(int j = 0; ret > 1 && j < C; j++) {
    vector<int> cands;
    for(auto [idx, a, b]: v) {
      cands.pb(dp[idx][a][b][i][j]);
    }
    sort(all(cands));
    cands.erase(unique(all(cands)), cands.end());
    if(sz(cands) == 1) continue;
    int go = 1;
    vector<vector<array<int, 3>>> ops(sz(cands));
    for(auto [idx, a, b]: v) {
      int cur = dp[idx][a][b][i][j];
      int iidx = lower_bound(all(cands), cur) - cands.begin();
      ops[iidx].pb({idx, a, b});
    }
    for(auto& x: ops) {
      updmax(go, me(x, depth+1) + 1);
      if(go >= ret) break;
    }
    if(updmin(ret, go)) {
      meopt[v] = {i, j};
    }
  }
  return medp[v] = ret;
}
void solve() {
  init();
  int n;
  cin >> n;
  vector<array<int, 3>> options;
  for(int a = 0; a < n; a++) {
    int x, y;
    cin >> x >> y;
    for(int i = 0; i < 6; i++) {
      options.pb({i, x, y});
    }
  }
  int ans = me(options, 0);
  cout << ans << endl;
  for(int guess = ans; guess > 0; guess--) {
    assert(me(options, 0) == guess);
    auto cand = meopt[options];
    cout << "? " << cand[0] << " " << cand[1] << endl;
    int dist;
    cin >> dist;
    vector<array<int, 3>> noptions;
    for(auto [idx, a, b]: options) {
      if(dp[idx][a][b][cand[0]][cand[1]] == dist) {
        noptions.pb({idx, a, b});
      }
    }
    swap(options, noptions);
  }
  set<int> seen;
  for(auto [idx, a, b]: options) seen.insert(idx);
  assert(sz(seen) == 1);
  cout << "! " << ALPHA[*seen.begin()] << endl;
}

// what would chika do
// are there edge cases?
// did you actually sort the thing instead of just thinking it?
// integer overflow?

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 4088kb

input:

1
9 0
8

output:

1
? 1 8
! S

result:

ok number is guessed.

Test #2:

score: 0
Accepted
time: 3ms
memory: 4084kb

input:

4
2 1
2 3
2 5
2 7
5
1

output:

2
? 0 0
? 0 6
! M

result:

ok number is guessed.

Test #3:

score: -100
Runtime Error

input:

1
2 4
-1

output:

2
? 0 0

result: