結果

問題 No.340 雪の足跡
ユーザー HachimoriHachimori
提出日時 2016-03-06 09:44:54
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,342 bytes
コンパイル時間 852 ms
コンパイル使用メモリ 69,192 KB
実行使用メモリ 11,604 KB
最終ジャッジ日時 2023-10-24 20:03:44
合計ジャッジ時間 16,049 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
11,544 KB
testcase_01 AC 5 ms
11,544 KB
testcase_02 AC 4 ms
11,548 KB
testcase_03 AC 4 ms
11,544 KB
testcase_04 AC 5 ms
11,548 KB
testcase_05 AC 4 ms
11,544 KB
testcase_06 WA -
testcase_07 AC 5 ms
11,548 KB
testcase_08 AC 4 ms
11,548 KB
testcase_09 AC 5 ms
11,544 KB
testcase_10 AC 4 ms
11,548 KB
testcase_11 AC 6 ms
11,544 KB
testcase_12 AC 5 ms
11,544 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 42 ms
11,548 KB
testcase_18 AC 34 ms
11,548 KB
testcase_19 AC 43 ms
11,548 KB
testcase_20 TLE -
testcase_21 TLE -
testcase_22 AC 4 ms
11,548 KB
testcase_23 AC 879 ms
11,552 KB
testcase_24 TLE -
testcase_25 AC 916 ms
11,556 KB
testcase_26 AC 57 ms
11,552 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 362 ms
11,552 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 838 ms
11,552 KB
testcase_33 AC 626 ms
11,552 KB
testcase_34 AC 824 ms
11,552 KB
testcase_35 TLE -
testcase_36 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#define r first
#define c second
using namespace std;
typedef pair<int, int> Point;
const int BUF = 1005;


int dr[] = {1, 0, -1, 0};
int dc[] = {0, 1, 0, -1};

int row, col;
bool canPass[BUF][BUF][4];


int sign(int v) {
    if (v > 0) return 1;
    if (v < 0) return -1;
    return 0;
}

void read() {
    memset(canPass, 0, sizeof(canPass));
    
    int nRoute;
    cin >> row >> col >> nRoute;
    
    for (int i = 0; i < nRoute; ++i) {
        int nPt;
        cin >> nPt;
        nPt++;
        
        vector<Point> ptList;
        for (int j = 0; j < nPt; ++j) {
            int v;
            cin >> v;
            ptList.push_back(Point(v / col, v % col));
        }
        
        for (int j = 0; j + 1 < nPt; ++j) {
            Point &cur = ptList[j];
            Point &nex = ptList[j + 1];
            for (int k = 0; k < 4; ++k) {
                if (!(sign(nex.r - cur.r) == sign(dr[k]) &&
                      sign(nex.c - cur.c) == sign(dc[k])))
                    continue;

                int cr = cur.r;
                int cc = cur.c;
                while (!(cr == nex.r && cc == nex.c)) {
                    canPass[cr][cc][k] = true;
                    canPass[cr + dr[k]][cc + dc[k]][(k + 2) % 4] = true;
                    cr += dr[k];
                    cc += dc[k];
                }
                
                break;
            }
        }
    }
}


void work() {
    static int cost[BUF][BUF];
    queue<Point> Q;
    
    memset(cost, -1, sizeof(cost));
    cost[0][0] = 0;
    Q.push(Point(0, 0));
    
    while (!Q.empty()) {
        Point cur = Q.front();
        Q.pop();
        
        if (cur.r == row - 1 && cur.c == col - 1) {
            cout << cost[cur.r][cur.c] << endl;
            return;
        }
        
        for (int i = 0; i < 4; ++i) {
            int nr = cur.r + dr[i];
            int nc = cur.c + dc[i];
            
            if (!canPass[cur.r][cur.c][i]) continue;
            if (!(0 <= nr && nr < row && 0 <= nc && nc < col)) continue;
            if (cost[nr][nc] != -1) continue;

            cost[nr][nc] = cost[cur.r][cur.c] + 1;
            Q.push(Point(nr, nc));
        }
    }

    cout << "Odekakedekinai.." << endl;
}


int main() {
    read();
    work();
    return 0;
}
0