QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#700785#9537. Chinese Chessucup-team008#RE 6ms4076kbC++179.7kb2024-11-02 13:23:422024-11-02 13:23:42

Judging History

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

  • [2024-11-02 13:23:42]
  • 评测
  • 测评结果:RE
  • 用时:6ms
  • 内存:4076kb
  • [2024-11-02 13:23:42]
  • 提交

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;
      }
    }
  }
  for(int i = 0; i < 6; i++) for(int a = 0; a < R; a++) for(int b = 0; b < C; b++) for(int c = 0; c < R; c++) for(int d = 0; d < C; d++) {
    if(dp[i][a][b][c][d] >= 200) dp[i][a][b][c][d] = -1;
  }
}

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

input:

1
9 0
8

output:

1
? 1 8
! S

result:

ok number is guessed.

Test #2:

score: 0
Accepted
time: 2ms
memory: 4076kb

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: 0
Accepted
time: 2ms
memory: 3796kb

input:

1
2 4
-1
1

output:

2
? 0 0
? 0 2
! X

result:

ok number is guessed.

Test #4:

score: 0
Accepted
time: 1ms
memory: 3800kb

input:

1
5 0
6

output:

1
? 3 6
! S

result:

ok number is guessed.

Test #5:

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

input:

1
6 0
6

output:

1
? 0 2
! S

result:

ok number is guessed.

Test #6:

score: 0
Accepted
time: 2ms
memory: 4060kb

input:

2
7 7
1 0
-1
6

output:

2
? 0 0
? 7 2
! S

result:

ok number is guessed.

Test #7:

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

input:

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

output:

2
? 0 0
? 0 3
! J

result:

ok number is guessed.

Test #8:

score: 0
Accepted
time: 6ms
memory: 3880kb

input:

6
0 7
1 6
2 8
0 5
7 6
8 2
-1
14

output:

2
? 0 0
? 8 1
! B

result:

ok number is guessed.

Test #9:

score: 0
Accepted
time: 5ms
memory: 3848kb

input:

7
6 5
3 0
3 2
4 1
4 0
2 4
5 2
5
7

output:

2
? 0 0
? 0 4
! J

result:

ok number is guessed.

Test #10:

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

input:

8
3 3
2 5
6 2
7 4
1 4
3 0
2 4
3 4
7
-1

output:

2
? 0 1
? 0 0
! S

result:

ok number is guessed.

Test #11:

score: 0
Accepted
time: 5ms
memory: 3956kb

input:

9
2 7
2 4
2 5
2 2
2 1
2 0
2 6
2 3
2 8
7
9

output:

2
? 3 1
? 0 0
! J

result:

ok number is guessed.

Test #12:

score: -100
Runtime Error

input:

10
4 0
0 0
5 0
7 0
8 0
1 0
6 0
9 0
2 0
3 0
9
0

output:

2
? 9 0
? 0 0

result: