結果

問題 No.340 雪の足跡
ユーザー nanophoto12nanophoto12
提出日時 2016-01-31 00:27:14
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,258 bytes
コンパイル時間 1,134 ms
コンパイル使用メモリ 102,276 KB
実行使用メモリ 21,432 KB
最終ジャッジ日時 2023-10-21 18:14:58
合計ジャッジ時間 6,143 ms
ジャッジサーバーID
(参考情報)
judge14 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
17,828 KB
testcase_01 AC 9 ms
13,480 KB
testcase_02 AC 9 ms
13,480 KB
testcase_03 WA -
testcase_04 AC 8 ms
13,480 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 9 ms
13,480 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 12 ms
13,480 KB
testcase_12 AC 11 ms
13,484 KB
testcase_13 AC 12 ms
13,484 KB
testcase_14 AC 202 ms
13,736 KB
testcase_15 AC 379 ms
13,772 KB
testcase_16 AC 112 ms
13,596 KB
testcase_17 AC 188 ms
13,596 KB
testcase_18 AC 431 ms
13,808 KB
testcase_19 AC 92 ms
13,520 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>
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];
bool ok[1001][1001];
bool visit[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;
        ok[i][j] = false;
        visit[i][j] = false;
    }
    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-1;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, 1001)
    {
        int c = 0;
        REP(j, 1001)
        {
            c+=xs[i][j];
            if(c > 0)
            {
                ok[i][j] = true;
            }
        }
    }
    REP(j, 1001)
    {
        int c = 0;
        REP(i, 1001)
        {
            c+=ys[i][j];
            if(c > 0)
            {
                ok[i][j] = true;
            }
        }
        
    }
    p shifts[4] = {p(0,-1), p(0,1), p(1,0),p(-1,0)};

    if(!ok[0][0])
    {
        cout << "Odekakedekinai.." << endl;
        return 0;
    }
    queue<p> nexts;
    nexts.push(p(0,0));
    int current = 0;
    while(!nexts.empty())
    {
        queue<p> t;
        while(!nexts.empty())
        {
            p c = nexts.front();
            nexts.pop();
            if(visit[c.first][c.second])
            {
                continue;
            }
            visit[c.first][c.second] = true;
            REP(i, 4)
            {
                auto nx = c.first + shifts[i].first;
                auto ny = c.second + shifts[i].second;
                if(nx >= 0 && nx < w)
                {
                    if(ny >= 0 && ny < h)
                    {
                        if(nx == w-1)
                        {
                            if(ny == h - 1)
                            {
                                cout << (current+1) << endl;
                                return 0;
                            }
                        }
                        if(ok[nx][ny] && !visit[nx][ny])
                        {
                            t.push(p(nx,ny));
                        }
                    }
                }
            }
        }
        current++;
        nexts = t;
    }
    cout << "Odekakedekinai.." << endl;
    return 0;
}
0