結果

問題 No.340 雪の足跡
ユーザー Tsuneo YoshiokaTsuneo Yoshioka
提出日時 2016-01-29 23:49:49
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 3,509 bytes
コンパイル時間 1,009 ms
コンパイル使用メモリ 103,616 KB
実行使用メモリ 19,548 KB
最終ジャッジ日時 2023-10-21 17:35:24
合計ジャッジ時間 6,709 ms
ジャッジサーバーID
(参考情報)
judge14 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 RE -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
4,348 KB
testcase_06 RE -
testcase_07 WA -
testcase_08 WA -
testcase_09 RE -
testcase_10 WA -
testcase_11 AC 3 ms
4,348 KB
testcase_12 RE -
testcase_13 AC 3 ms
4,348 KB
testcase_14 RE -
testcase_15 AC 18 ms
4,828 KB
testcase_16 RE -
testcase_17 AC 23 ms
5,212 KB
testcase_18 AC 19 ms
4,904 KB
testcase_19 AC 22 ms
5,220 KB
testcase_20 AC 189 ms
15,780 KB
testcase_21 RE -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 37 ms
5,896 KB
testcase_27 RE -
testcase_28 AC 31 ms
5,728 KB
testcase_29 AC 221 ms
17,316 KB
testcase_30 RE -
testcase_31 RE -
testcase_32 AC 263 ms
19,548 KB
testcase_33 AC 205 ms
17,552 KB
testcase_34 AC 259 ms
19,460 KB
testcase_35 AC 180 ms
15,856 KB
testcase_36 AC 179 ms
15,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <fstream>
#include <iostream>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <queue>
#include <stdexcept>

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cassert>
#include <unistd.h>
#include <string.h>

#include <stack>
#include <list>

using namespace std;

int main(int argc, const char * argv[])
{
    // sleep(1000);
    // insert code here...
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(15);

    int W, H, N;
    cin >> W >> H >> N;
    vector< vector<bool> > ma(H, vector<bool>(W, false));
    vector< vector< pair<int, int> > >hlines(H);
    vector< vector< pair<int, int> > >wlines(H);
    
    for(int n=0;n<N;n++){
        int M;
        cin >> M; M++;
        int prev_h, prev_w;
        
        for(int m=0;m<M;m++){
            int B;
            cin >> B;
            int w, h;
            w = B%W;
            h = B/W;
             //   cout << "m=" << m << ",B=" << B << " w=" << w << ",h=" << h << endl;
            if(m>=1){
                if(prev_h == h){
                    int w1 = prev_w, w2 = w;
                    if(w2<w1){
                        swap(w1, w2);
                    }
                    hlines[h].push_back(make_pair(w1, w2));
                }else if(prev_w == w){
                    int h1 = prev_h, h2 = h;
                    if(h2<h1){
                        swap(h1, h2);
                    }
                    wlines[w].push_back(make_pair(h1, h2));
                }else{
                    printf("Wrong......\n");
                    exit(1);
                }



            }            
            
            prev_w = w;
            prev_h = h;
        }
    }




    for(int h=0;h<H;h++){
        sort(hlines[h].begin(), hlines[h].end());
        int endpos = -1;
        int cur = 0;
        for(int w=0;w<W;w++){
            if(cur < hlines[h].size() && hlines[h][cur].first==w){
                endpos = max(endpos, hlines[h][cur].second);
                cur++;
            }
            if(w<=endpos){
                ma[h][w] = true;
            }
        }
    }
    for(int w=0;w<W;w++){
        sort(wlines[w].begin(), wlines[w].end());
        int endpos = -1;
        int cur = 0;
        for(int h=0;h<H;h++){
            if(cur < wlines[w].size() && wlines[w][cur].first==h){
                endpos = max(endpos, wlines[w][cur].second);
                cur++;
            }
            if(h<=endpos){
                ma[h][w] = true;
            }
        }
    }
    queue< pair<int, int> > q;
    vector<int> used(W*H, false);
    
    q.push(make_pair(0,0));
    while(!q.empty()){
        auto pa = q.front();
        q.pop();
        int c = pa.first;
        int b = pa.second;
        //cout << "c=" << c << ", b=" << b << ", w=" << b%W << ", h=" << b/W << endl;
        if(b==W*H-1){
            cout << c << endl;
            exit(0);
        }
        if(used[b]){
            continue;
        }
        used[b] = true;
        
        int dx[]={0,1,0,-1};
        int dy[]={1,0,-1,0};
        for(int d=0;d<4;d++){
            int x = (b%W)+dx[d];
            int y = (b/W)+dy[d];
            if(x<0 || x>=W || y<0 || y>=H){
                continue;
            }
            int newb = y*W+x;
            q.push(make_pair(c+1, newb));
        }
    }
    cout << "Odekakedekinai.." << endl;






    return 0;
}


0