結果

問題 No.340 雪の足跡
ユーザー nanophoto12nanophoto12
提出日時 2016-01-31 23:13:37
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,977 bytes
コンパイル時間 2,816 ms
コンパイル使用メモリ 96,624 KB
実行使用メモリ 34,460 KB
最終ジャッジ日時 2023-10-21 18:26:14
合計ジャッジ時間 5,792 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 5 ms
15,424 KB
testcase_02 AC 5 ms
15,428 KB
testcase_03 WA -
testcase_04 AC 6 ms
15,428 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 8 ms
15,428 KB
testcase_12 AC 7 ms
15,432 KB
testcase_13 AC 8 ms
15,432 KB
testcase_14 AC 202 ms
15,684 KB
testcase_15 AC 374 ms
15,720 KB
testcase_16 AC 107 ms
15,544 KB
testcase_17 AC 184 ms
15,544 KB
testcase_18 AC 425 ms
15,756 KB
testcase_19 AC 93 ms
15,468 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
#include <sstream>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <functional>
using namespace std;

typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)

#define p pair<int,int>

#include <iostream>
using namespace std;

int xs[1001][1001];
int ys[1001][1001];
int dist[1001][1001];

int main(){
    int w, h, n;
    cin>>w >> h >> n;
    REP(i, 1001)REP(j,1001)
    {
        xs[i][j] = 0;
        ys[i][j] = 0;
        dist[i][j] = 1000000000;
    }
    for(int i = 0;i < n;i++)
    {
        int m;
        cin >> m;
        vector<int> ms(m);
        for(int j = 0;j < m;j++)
        {
            cin >> ms[j];
        }
        for(int j = 0;j < m;j++)
        {
            int a = ms[j];
            int b = ms[j+1];
            int sx = a % w;
            int sy = a / w;
            int ex = b % w;
            int ey = b / w;
            if(sx == ex)
            {
                xs[sx][min(sy, ey)] += 1;
                xs[sx][max(sy, ey) + 1] -= 1;
            }
            else
            {
                ys[min(sx, ex)][sy] += 1;
                ys[max(sx, ex)+1][sy] -= 1;
            }
        }
    }
    REP(i, w+1)
    {
        int c = 0;
        REP(j, h+1)
        {
            c+=xs[i][j];
            xs[i][j] = c;
        }
    }
    REP(j, h+1)
    {
        int c = 0;
        REP(i, w+1)
        {
            c+=ys[i][j];
            ys[i][j] = c;
        }
    }
    if(!(xs[0][0] || ys[0][0]))
    {
        cout << "Odekakedekinai.." << endl;
        return 0;
    }
    priority_queue<tuple<int,int,int>,vector<tuple<int,int,int>>,greater<tuple<int,int,int>>> nexts;
    nexts.push(make_tuple(-0,0,0));
    while(!nexts.empty())
    {
        const auto c = nexts.top(); nexts.pop();
        const int x = get<1>(c);
        const int y = get<2>(c);
        int z = get<0>(c);
        if(z>dist[x][y])
        {
            continue;
        }
        if(x == w-1 && y == h-1)
        {
            cout << z << endl;
            return 0;
        }
        z++;
        if(x > 0 && ys[x-1][y] && dist[x-1][y]>z)
        {
            dist[x-1][y] = z;
            nexts.push(make_tuple(z, x-1,y));
        }
        if(x < w-1 && ys[x][y] && dist[x+1][y]>z)
        {
            dist[x+1][y] = z;
            nexts.push(make_tuple(z,x+1,y));
        }
        if(y > 0 && xs[x][y-1] && dist[x][y-1] > z)
        {
            dist[x][y-1] = z;
            nexts.push(make_tuple(z, x,y-1));
        }
        if(y < h-1 && xs[x][y] && dist[x][y+1] > z)
        {
            dist[x][y+1] = z;
            nexts.push(make_tuple(z, x,y+1));
        }
    }
    cout << "Odekakedekinai.." << endl;
    return 0;
}
0