QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#167767#7180. Forward-Capturing Pawnsucup-team052#TL 95ms58072kbC++146.7kb2023-09-07 17:14:552023-09-07 17:14:56

Judging History

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

  • [2023-09-07 17:14:56]
  • 评测
  • 测评结果:TL
  • 用时:95ms
  • 内存:58072kb
  • [2023-09-07 17:14:55]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
using namespace std;

typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;

template <typename _T>
inline void read(_T &f) {
    f = 0; _T fu = 1; char c = getchar();
    while (c < '0' || c > '9') { if (c == '-') { fu = -1; } c = getchar(); }
    while (c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    f *= fu;
}

template <typename T>
void print(T x) {
    if (x < 0) putchar('-'), x = -x;
    if (x < 10) putchar(x + 48);
    else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
    print(x); putchar(t);
}

const int N = 1e6 + 5;
const int dx[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy[8] = {1, 0, -1, 1, -1, 1, 0, -1};

vector <int> adj[N];
queue <int> q;
int dp[N], out[N];
int T;

int get_state(int a, int b, int c, int d, int e, int f, int g) {
    int st = 0;
    st = st * 8 + a;
    st = st * 8 + b;
    st = st * 8 + c;
    st = st * 8 + d;
    st = st * 8 + e;
    st = st * 8 + f;
    st = st * 2 + g;
    return st;
}

void add(int u, int v) {
    adj[v].push_back(u); ++out[u];
}

int main() {
    for (int a = 1; a <= 8; a++) {
        for (int b = 1; b <= 8; b++) {
            for (int c = 1; c <= 8; c++) {
                for (int d = 2; d <= 8; d++) {
                    if (a == c && b == d) continue;
                    for (int e = 1; e <= 8; e++) {
                        for (int f = 1; f <= 8; f++) {
                            if (a == e && b == f) continue;
                            if (c == e && d == f) continue;
                            for (int g = 0; g <= 1; g++) {
                                int nst = get_state(a, b, c, d, e, f, g);
                                // if (nst > 900000) fprintf(stderr, "nst = %d\n", nst);
                                if (g == 0) {
                                    for (int dd = 0; dd < 8; dd++) {
                                        int x = a + dx[dd], y = b + dy[dd];
                                        if (x >= 1 && y >= 1 && x <= 8 && y <= 8 && (x != c || y != d)) {
                                            if (x == e && y == f) {
                                                dp[nst] = 1;
                                            } else {
                                                int st = get_state(x, y, c, d, e, f, 1);
                                                add(nst, st);
                                            }
                                        }
                                    }
                                    if (d != 8) {
                                        int up = (d == 2 ? 2 : 1);
                                        if (a == c && b == d + 1) up = 1;
                                        for (int i = 1; i <= up; i++) {
                                            int x = c, y = d + i;
                                            if (x >= 1 && y >= 1 && x <= 8 && y <= 8 && (x != a || y != b)) {
                                                if (x == e && y == f) {
                                                    dp[nst] = 1;
                                                } else {
                                                    int st = get_state(a, b, x, y, e, f, 1);
                                                    add(nst, st);
                                                }
                                            }
                                        }
                                    } else {
                                        dp[nst] = 1;
                                    }
                                } else {
                                    auto check = [&](int x, int y) {
                                        if (abs(x - a) <= 1 && abs(y - b) <= 1) return 0;
                                        if (x == c && y == d + 1) return 0;
                                        if (x == c && y == d + 2 && d == 2) return 0;
                                        return 1;
                                    };
                                    int can_move = 0;
                                    for (int dd = 0; dd < 8; dd++) {
                                        int x = e + dx[dd], y = f + dy[dd];
                                        if (x >= 1 && y >= 1 && x <= 8 && y <= 8) {
                                            if (x == a && y == b) {
                                                dp[nst] = -1;
                                                // fprintf(stderr, "happy\n");
                                            } else if (x == c && y == d) {
                                                if (abs(a - c) <= 1 && abs(b - d) <= 1) continue;
                                                dp[nst] = -1;
                                            } else {
                                                if (!can_move && check(x, y)) can_move = 1;
                                                int st = get_state(a, b, c, d, x, y, 0);
                                                add(nst, st);
                                            }
                                        }
                                    }
                                    if (!can_move && check(e, f)) dp[nst] = -1;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    for (int i = 0; i < N; i++) {
        if (dp[i]) {
            q.push(i);
        }
    }
    while (!q.empty()) {
        int u = q.front(); q.pop();
        for (auto v : adj[u]) {
            if (!dp[v]) {
                int vg = v % 2;
                if (vg == 0 && dp[u] == 1) {
                    dp[v] = 1; q.push(v);
                } else if (vg == 1 && dp[u] == -1) {
                    dp[v] = -1; q.push(v);
                } else {
                    --out[v];
                    if (out[v] == 0) {
                        if (vg == 0) dp[v] = -1;
                        else dp[v] = 1;
                        q.push(v);
                    }
                }
            }
        }
    }
    read(T);
    while (T--) {
        int a, b, c, d, e, f, g;
        char t;
        cin >> t; a = t - 'a' + 1;
        cin >> t; b = t - '0';
        cin >> t; c = t - 'a' + 1;
        cin >> t; d = t - '0';
        cin >> t; e = t - 'a' + 1;
        cin >> t; f = t - '0';
        cin >> t; g = (t == 'b');
        int st = get_state(a, b, c, d, e, f, g);
        printf("%s\n", dp[st] == 1 ? "Win" : "Draw");
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 95ms
memory: 58072kb

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
Time Limit Exceeded

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:

Draw
Draw
Draw
Win
Win
Win
Win
Win
Win
Win
Win
Win
Draw
Draw
Draw
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Win
Draw
Win
Draw
Win
Draw
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: