QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#64553#4433. Kitten and RoombaAs3b_team_f_masr#TL 0ms0kbC++5.3kb2022-11-24 23:49:442022-11-24 23:50:17

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-24 23:50:17]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2022-11-24 23:49:44]
  • 提交

answer

#include <bits/stdc++.h>

typedef long double ld;
typedef long long ll;
using namespace std;
int di[] = {1, 0, -1, -1, 0, 1, -1, 1};
int dj[] = {1, 1, 0, -1, -1, 0, 1, -1};
const ll oo = 1e18, MOD = 998244353;
const int N = 2005, M = 1e6 + 5;
const ld PI = acos(-1.0), EPS = 1e-9;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int t, n, m, vis[N][N][2][2][2][2], id;
char rows[N], cols[N], path[N], a[N][N];
bool dp[N][N][2][2][2][2];

bool solve(int i, int j, int doner, int donec, int snaker, int snakec) {
    bool &ret = dp[i][j][doner][donec][snaker][snakec];
    if (i == n - 1 && j == m - 1) return ret = 1;
    if (vis[i][j][doner][donec][snaker][snakec] == id) return ret;
    vis[i][j][doner][donec][snaker][snakec] = id;
    if (i != n - 1 && a[i + 1][j] != '#') {
        if (a[i + 1][j] == '.' || (a[i + 1][j] == 'O' && !donec) || (a[i + 1][j] == '@' && donec))
            ret |= solve(i + 1, j, 0, donec, a[i + 1][j] == 'O', snakec | (a[i + 1][j] == 'O'));
        if (a[i + 1][j] == '@' && !donec) ret |= solve(i + 1, j, 1, 0, 0, snakec);
        if (a[i + 1][j] == '@' && !donec && !snakec) ret |= solve(i + 1, j, 0, 1, 0, 0);
        if (a[i + 1][j] == 'O' && donec) ret |= solve(i + 1, j, 1, 1, 1, 1);
    }
    if (j != m - 1 && a[i][j + 1] != '#') {
        if (a[i][j + 1] == '.' || (a[i][j + 1] == 'O' && !doner) || (a[i][j + 1] == '@' && doner))
            ret |= solve(i, j + 1, doner, 0, snaker | (a[i][j + 1] == 'O'), a[i][j + 1] == 'O');
        if (a[i][j + 1] == '@' && !doner) ret |= solve(i, j + 1, 0, 1, snaker, 0);
        if (a[i][j + 1] == '@' && !doner && !snaker) ret |= solve(i, j + 1, 1, 0, 0, 0);
        if (a[i][j + 1] == 'O' && doner) ret |= solve(i, j + 1, 1, 1, 1, 1);
    }
    return ret;
}

void build(int i, int j, int doner, int donec, int snaker, int snakec) {
    if (i == n - 1 && j == m - 1) return;
    if (i != n - 1 && a[i + 1][j] != '#') {
        if (a[i + 1][j] == '.' || (a[i + 1][j] == 'O' && !donec) || (a[i + 1][j] == '@' && donec)) {
            if (dp[i + 1][j][0][donec][a[i + 1][j] == 'O'][snakec | (a[i + 1][j] == 'O')]) {
                path[i + j] = 'D';
                build(i + 1, j, 0, donec, a[i + 1][j] == 'O', snakec | (a[i + 1][j] == 'O'));
                return;
            }
        }
        if (a[i + 1][j] == '@' && !donec) {
            if (dp[i + 1][j][1][0][0][snakec]) {
                path[i + j] = 'D', rows[i + 1] = 'T';
                build(i + 1, j, 1, 0, 0, snakec);
                return;
            }
        }
        if (a[i + 1][j] == '@' && !donec && !snakec) {
            if (dp[i + 1][j][0][1][0][0]) {
                path[i + j] = 'D', cols[j] = 'T';
                build(i + 1, j, 0, 1, 0, 0);
                return;
            }
        }
        if (a[i + 1][j] == 'O' && donec) {
            if (dp[i + 1][j][1][1][1][1]) {
                path[i + j] = 'D', rows[i + 1] = 'T';
                build(i + 1, j, 1, 1, 1, 1);
                return;
            }
        }
    }
    if (j != m - 1 && a[i][j + 1] != '#') {
        if (a[i][j + 1] == '.' || (a[i][j + 1] == 'O' && !doner) || (a[i][j + 1] == '@' && doner)) {
            if (dp[i][j + 1][doner][0][snaker | (a[i][j + 1] == 'O')][a[i][j + 1] == 'O']) {
                path[i + j] = 'P';
                build(i, j + 1, doner, 0, snaker | (a[i][j + 1] == 'O'), a[i][j + 1] == 'O');
                return;
            }
        }
        if (a[i][j + 1] == '@' && !doner) {
            if (dp[i][j + 1][0][1][snaker][0]) {
                path[i + j] = 'P', cols[j + 1] = 'T';
                build(i, j + 1, 0, 1, snaker, 0);
                return;
            }
        }
        if (a[i][j + 1] == '@' && !doner && !snaker) {
            if (dp[i][j + 1][1][0][0][0]) {
                path[i + j] = 'P', rows[i] = 'T';
                build(i, j + 1, 1, 0, 0, 0);
                return;
            }
        }
        if (a[i][j + 1] == 'O' && doner) {
            if (dp[i][j + 1][1][1][1][1]) {
                path[i + j] = 'P', cols[j + 1] = 'T';
                build(i, j + 1, 1, 1, 1, 1);
                return;
            }
        }
    }
}

//#define endl '\n'
int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    //freopen("farm.in", "r", stdin);
    //memset(dp, -1, sizeof dp);
    cin >> t;
    while (t--) {
        id++;
        cin >> n >> m;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) cin >> a[i][j];
        }
        if (!solve(0, 0, 0, 0, a[0][0] == 'O', a[0][0] == 'O')) cout << "NIE" << endl;
        else {
            cout << "TAK" << endl;
            for (int i = 0; i < n; i++) rows[i] = 'N';
            for (int i = 0; i < m; i++) cols[i] = 'N';
            build(0, 0, 0, 0, a[0][0] == 'O', a[0][0] == 'O');
            for (int i = 0; i < n; i++) cout << rows[i];
            cout << endl;
            for (int i = 0; i < m; i++) cout << cols[i];
            cout << endl;
            for (int i = 0; i < n + m - 1; i++) cout << path[i];
            cout << endl;
        }
    }

    return 0;
}

詳細信息

Test #1:

score: 0
Time Limit Exceeded

input:

2
1000000 315562
969409 917725
324847 719085
524235 603427
576843 433171
75335 238378
266746 487233
80422 95099
594363 96140
858172 261406
958326 466109
233845 350950
863969 345645
689972 81395
395383 27274
93913 208983
523722 380358
108074 172341
130041 692304
737158 383812
752080 33646
154356 6672...

output:


result: