提出 #49939541


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
namespace lzyqwq {
    const int N = 65; bool vis[N][N][N][N];
    int n, cnt; char ma[N][N];
    struct node {
        int xa, ya, xb, yb, f;
    } st; queue<node> q;
    int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
    void Main() {
        cin.tie(0), cout.tie(0), ios::sync_with_stdio(0); cin >> n;
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= n; ++j) {
                cin >> ma[i][j];
                if (ma[i][j] == 'P') {
                    ++cnt; 
                    if (cnt == 1) st.xa = i, st.ya = j;
                    else st.xb = i, st.yb = j;
                }
            }
        }
        st.f = 0; q.emplace(st); vis[st.xa][st.ya][st.xb][st.yb] = 1;
        while (q.size()) {
            node t = q.front(); q.pop();
            if (t.xa == t.xb && t.ya == t.yb) return void(cout << t.f);
            for (int i = 0; i < 4; ++i) {
                int xu = t.xa + dx[i], yu = t.ya + dy[i];
                int xv = t.xb + dx[i], yv = t.yb + dy[i];
                node tmp; tmp.f = t.f + 1;
                if (xu > 0 && xu <= n && yu > 0 && yu <= n && ma[xu][yu] != '#') 
                    tmp.xa = xu, tmp.ya = yu;
                else tmp.xa = t.xa, tmp.ya = t.ya;
                if (xv > 0 && xv <= n && yv > 0 && yv <= n && ma[xv][yv] != '#') 
                    tmp.xb = xv, tmp.yb = yv;
                else tmp.xb = t.xb, tmp.yb = t.yb;
                if (vis[tmp.xa][tmp.ya][tmp.xb][tmp.yb]) continue;
                vis[tmp.xa][tmp.ya][tmp.xb][tmp.yb] = 1;
                q.emplace(tmp);
            }
        }
        cout << -1;
    }
}
signed main() { return lzyqwq::Main(), 0; }

提出情報

提出日時
問題 D - Synchronized Players
ユーザ newbie_lzy
言語 C++ 20 (gcc 12.2)
得点 400
コード長 1742 Byte
結果 AC
実行時間 144 ms
メモリ 18548 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 3
AC × 55
セット名 テストケース
Sample sample00.txt, sample01.txt, sample02.txt
All sample00.txt, sample01.txt, sample02.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt, testcase20.txt, testcase21.txt, testcase22.txt, testcase23.txt, testcase24.txt, testcase25.txt, testcase26.txt, testcase27.txt, testcase28.txt, testcase29.txt, testcase30.txt, testcase31.txt, testcase32.txt, testcase33.txt, testcase34.txt, testcase35.txt, testcase36.txt, testcase37.txt, testcase38.txt, testcase39.txt, testcase40.txt, testcase41.txt, testcase42.txt, testcase43.txt, testcase44.txt, testcase45.txt, testcase46.txt, testcase47.txt, testcase48.txt, testcase49.txt, testcase50.txt, testcase51.txt
ケース名 結果 実行時間 メモリ
sample00.txt AC 1 ms 3588 KiB
sample01.txt AC 1 ms 3508 KiB
sample02.txt AC 1 ms 3900 KiB
testcase00.txt AC 31 ms 10780 KiB
testcase01.txt AC 10 ms 7996 KiB
testcase02.txt AC 22 ms 8676 KiB
testcase03.txt AC 9 ms 9240 KiB
testcase04.txt AC 22 ms 10748 KiB
testcase05.txt AC 32 ms 7860 KiB
testcase06.txt AC 29 ms 9428 KiB
testcase07.txt AC 51 ms 8248 KiB
testcase08.txt AC 45 ms 6016 KiB
testcase09.txt AC 43 ms 7052 KiB
testcase10.txt AC 53 ms 8692 KiB
testcase11.txt AC 69 ms 8356 KiB
testcase12.txt AC 1 ms 3860 KiB
testcase13.txt AC 39 ms 11708 KiB
testcase14.txt AC 25 ms 8004 KiB
testcase15.txt AC 59 ms 9176 KiB
testcase16.txt AC 74 ms 7616 KiB
testcase17.txt AC 7 ms 3752 KiB
testcase18.txt AC 9 ms 4004 KiB
testcase19.txt AC 7 ms 13284 KiB
testcase20.txt AC 9 ms 3828 KiB
testcase21.txt AC 7 ms 10872 KiB
testcase22.txt AC 59 ms 16476 KiB
testcase23.txt AC 29 ms 17252 KiB
testcase24.txt AC 26 ms 10516 KiB
testcase25.txt AC 86 ms 15056 KiB
testcase26.txt AC 15 ms 10008 KiB
testcase27.txt AC 108 ms 18548 KiB
testcase28.txt AC 41 ms 12312 KiB
testcase29.txt AC 99 ms 16896 KiB
testcase30.txt AC 66 ms 11024 KiB
testcase31.txt AC 114 ms 15900 KiB
testcase32.txt AC 3 ms 5224 KiB
testcase33.txt AC 80 ms 15572 KiB
testcase34.txt AC 144 ms 16764 KiB
testcase35.txt AC 119 ms 15880 KiB
testcase36.txt AC 13 ms 6896 KiB
testcase37.txt AC 41 ms 11848 KiB
testcase38.txt AC 1 ms 3848 KiB
testcase39.txt AC 104 ms 15820 KiB
testcase40.txt AC 38 ms 9668 KiB
testcase41.txt AC 1 ms 3632 KiB
testcase42.txt AC 127 ms 14504 KiB
testcase43.txt AC 94 ms 15388 KiB
testcase44.txt AC 124 ms 15096 KiB
testcase45.txt AC 49 ms 11296 KiB
testcase46.txt AC 96 ms 15488 KiB
testcase47.txt AC 11 ms 7404 KiB
testcase48.txt AC 117 ms 13408 KiB
testcase49.txt AC 36 ms 9388 KiB
testcase50.txt AC 68 ms 11236 KiB
testcase51.txt AC 141 ms 14204 KiB