QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#165253#7180. Forward-Capturing Pawnsucup-team087#WA 161ms58664kbC++147.1kb2023-09-05 17:00:232023-09-05 17:00:24

Judging History

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

  • [2023-09-05 17:00:24]
  • 评测
  • 测评结果:WA
  • 用时:161ms
  • 内存:58664kb
  • [2023-09-05 17:00:23]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


int lens[64];
int adj[64][8];

// White king, White pawn, Black king
int V;
int ids[64][64][64][2];
vector<int> turnOf;
vector<vector<int>> graph, hparg;

bool checkedA(int a, int b, int c) {
  const int ax = a / 8, ay = a % 8;
  // const int bx = b / 8, by = b % 8;
  const int cx = c / 8, cy = c % 8;
  if (abs(ax - cx) <= 1 && abs(ay - cy) <= 1) return true;
  return false;
}
bool checkedC(int a, int b, int c) {
  const int ax = a / 8, ay = a % 8;
  const int bx = b / 8, by = b % 8;
  const int cx = c / 8, cy = c % 8;
  if (abs(ax - cx) <= 1 && abs(ay - cy) <= 1) return true;
  if (by == cy) {
    if (bx - 1 == cx) return true;
    if (bx == 6 && cx == 4 && make_pair(ax, ay) != make_pair(5, by)) return true;
  }
  return false;
}
bool isReasonable(int a, int b, int c, int t) {
  const int ax = a / 8, ay = a % 8;
  const int bx = b / 8, by = b % 8;
  const int cx = c / 8, cy = c % 8;
  // 1
  if (a == b) return false;
  if (a == c) return false;
  if (b == c) return false;
  // 2
  if (bx == 0 || bx == 7) return false;
  // 3
  if (abs(ax - cx) <= 1 && abs(ay - cy) <= 1) return false;
  if (t == 0) {
    if (checkedC(a, b, c)) return false;
  } else {
    if (checkedA(a, b, c)) return false;
  }
  return true;
}

int readPiece() {
  char buf[10];
  scanf("%s", buf);
  const int x = '8' - buf[1];
  const int y = buf[0] - 'a';
  assert(0 <= x); assert(x < 8);
  assert(0 <= y); assert(y < 8);
  return x * 8 + y;
}
int readTurn() {
  char c;
  scanf(" %c", &c);
  return (c == 'b') ? 1 : 0;
}
int main() {
  memset(adj, ~0, sizeof(adj));
  for (int a = 0; a < 64; ++a) {
    const int x = a / 8, y = a % 8;
    for (int dx = -1; dx <= +1; ++dx) for (int dy = -1; dy <= +1; ++dy) if (dx || dy) {
      const int xx = x + dx;
      const int yy = y + dy;
      if (0 <= xx && xx < 8 && 0 <= yy && yy < 8) {
        const int b = xx * 8 + yy;
        adj[a][lens[a]++] = b;
      }
    }
  }
  
  V = 2;
  memset(ids, ~0, sizeof(ids));
  turnOf = {0, 1};
  for (int a = 0; a < 64; ++a) for (int b = 0; b < 64; ++b) for (int c = 0; c < 64; ++c) {
    for (int t = 0; t < 2; ++t) {
      if (isReasonable(a, b, c, t)) {
        ids[a][b][c][t] = V++;
        turnOf.push_back(t);
      }
    }
  }
// cerr<<"V = "<<V<<endl;
  graph.assign(V, {});
  graph[1].push_back(1);
  for (int a = 0; a < 64; ++a) for (int b = 0; b < 64; ++b) for (int c = 0; c < 64; ++c) {
    const int ax = a / 8, ay = a % 8;
    const int bx = b / 8, by = b % 8;
    const int cx = c / 8, cy = c % 8;
    for (int t = 0; t < 2; ++t) {
      const int u = ids[a][b][c][t];
      if (~u) {
        if (t == 0) {
          // king
          for (int h = 0; h < lens[a]; ++h) {
            const int aa = adj[a][h];
            const int v = ids[aa][b][c][t ^ 1];
            if (~v) {
// if(u==90324)cerr<<make_pair(aa/8,aa%8)<<" "<<v<<endl;
              graph[u].push_back(v);
            }
          }
          // pawn
          for (int bbx = bx - 1; bbx >= ((bx == 6) ? 4 : (bx - 1)); --bbx) {
            const int bby = by;
            const int bb = bbx * 8 + bby;
            const int v = ids[a][bb][c][t ^ 1];
            if (~v) {
              graph[u].push_back(v);
            } else if (bbx == 0) {
              // promotion
              if (abs(bbx - cx) <= 1 && abs(bby - cy) <= 1) {
                if (abs(bbx - ax) <= 1 && abs(bby - ay) <= 1) {
// if(u==54374||u==54376||u==54386||u==54394||u==54396)cerr<<__LINE__<<" promo "<<u<<" "<<make_pair(bbx,bby)<<endl;
                  graph[u].push_back(0);
                } else {
// if(u==54374||u==54376||u==54386||u==54394||u==54396)cerr<<__LINE__<<" promo "<<u<<" "<<make_pair(bbx,bby)<<endl;
                  graph[u].push_back(1);
                }
              } else {
// if(u==54374||u==54376||u==54386||u==54394||u==54396)cerr<<__LINE__<<" promo "<<u<<" "<<make_pair(bbx,bby)<<endl;
                graph[u].push_back(0);
              }
            }
          }
        } else {
          // king
          for (int h = 0; h < lens[c]; ++h) {
            const int cc = adj[c][h];
            const int v = ids[a][b][cc][t ^ 1];
            if (~v) {
              graph[u].push_back(v);
            } else if (cc == b) {
              const int ccx = cc / 8, ccy = cc % 8;
              if (abs(ccx - ax) <= 1 && abs(ccy - ay) <= 1) {
                // invalid capture
              } else {
                graph[u].push_back(1);
              }
            }
          }
// if(u==54385)cerr<<__LINE__<<" "<<graph[u]<<endl;
          if (graph[u].empty()) {
            // checkmate or stalemate
            if (!checkedC(a, b, c)) {
              graph[u].push_back(1);
            }
          }
        }
      }
    }
  }
  
  vector<int> deg(V);
  hparg.assign(V, {});
  for (int u = 0; u < V; ++u) {
    deg[u] = graph[u].size();
    for (const int v : graph[u]) {
      hparg[v].push_back(u);
    }
  }
  vector<int> ans(V, 0);
  queue<int> que;
  for (int u = 0; u < V; ++u) if (deg[u] == 0) {
    que.push(u);
  }
  for (; !que.empty(); ) {
    // v: Win
    const int v = que.front();
    que.pop();
    ans[v] = 1;
    for (const int u : hparg[v]) {
      if (turnOf[u] == 0) {
        if (deg[u]) {
          que.push(u);
        }
        deg[u] = 0;
      } else {
        if (--deg[u] == 0) {
          que.push(u);
        }
      }
    }
  }
  
  for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
    const int a = readPiece();
    const int b = readPiece();
    const int c = readPiece();
    const int t = readTurn();
    
    assert(isReasonable(a, b, c, t));
    const int u = ids[a][b][c][t];
// cerr<<a<<" "<<b<<" "<<c<<" "<<t<<": "<<u<<endl;
    assert(~u);
    puts(ans[u] ? "Win" : "Draw");
  }
#ifndef LOCAL
  break;
#endif
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 93ms
memory: 58664kb

input:

6
a2 d7 e7 w
b6 d7 e7 b
b6 d7 e7 w
b5 a2 b2 w
a6 a2 a4 b
g6 g7 h8 b

output:

Draw
Draw
Win
Win
Draw
Draw

result:

ok 6 lines

Test #2:

score: -100
Wrong Answer
time: 161ms
memory: 58612kb

input:

332912
h8 h7 f8 b
h8 h7 f8 w
h8 h7 e8 b
h8 h7 e8 w
h8 h7 d8 b
h8 h7 d8 w
h8 h7 c8 b
h8 h7 c8 w
h8 h7 b8 b
h8 h7 b8 w
h8 h7 a8 b
h8 h7 a8 w
h8 h7 f7 b
h8 h7 f7 w
h8 h7 e7 b
h8 h7 e7 w
h8 h7 d7 b
h8 h7 d7 w
h8 h7 c7 b
h8 h7 c7 w
h8 h7 b7 b
h8 h7 b7 w
h8 h7 a7 b
h8 h7 a7 w
h8 h7 h6 b
h8 h7 h6 w
h8 h7 g...

output:

Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
...

result:

wrong answer 1st lines differ - expected: 'Draw', found: 'Win'