結果

問題 No.340 雪の足跡
ユーザー 小指が強い人小指が強い人
提出日時 2016-06-03 03:28:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 431 ms / 1,000 ms
コード長 4,290 bytes
コンパイル時間 1,833 ms
コンパイル使用メモリ 176,444 KB
実行使用メモリ 19,284 KB
最終ジャッジ日時 2024-04-19 08:06:19
合計ジャッジ時間 8,495 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,640 KB
testcase_01 AC 2 ms
7,784 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
7,644 KB
testcase_04 AC 2 ms
7,776 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
7,780 KB
testcase_07 AC 3 ms
7,756 KB
testcase_08 AC 2 ms
7,784 KB
testcase_09 AC 3 ms
7,756 KB
testcase_10 AC 2 ms
7,796 KB
testcase_11 AC 4 ms
7,884 KB
testcase_12 AC 4 ms
8,032 KB
testcase_13 AC 4 ms
8,124 KB
testcase_14 AC 23 ms
13,984 KB
testcase_15 AC 27 ms
9,932 KB
testcase_16 AC 22 ms
9,104 KB
testcase_17 AC 35 ms
10,100 KB
testcase_18 AC 29 ms
14,064 KB
testcase_19 AC 36 ms
14,196 KB
testcase_20 AC 315 ms
12,188 KB
testcase_21 AC 193 ms
11,472 KB
testcase_22 AC 5 ms
8,396 KB
testcase_23 AC 367 ms
15,388 KB
testcase_24 AC 301 ms
11,484 KB
testcase_25 AC 336 ms
14,412 KB
testcase_26 AC 54 ms
8,708 KB
testcase_27 AC 12 ms
7,960 KB
testcase_28 AC 48 ms
9,436 KB
testcase_29 AC 369 ms
16,304 KB
testcase_30 AC 249 ms
16,084 KB
testcase_31 AC 381 ms
18,780 KB
testcase_32 AC 429 ms
19,148 KB
testcase_33 AC 328 ms
19,280 KB
testcase_34 AC 431 ms
19,280 KB
testcase_35 AC 349 ms
19,156 KB
testcase_36 AC 349 ms
19,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> veci;
typedef vector<string> vecs;
template<class T,class U> using Hash=unordered_map<T,U>;

#define REP(i, a, n) for(ll i = a; i < n; i++)
#define RREP(i, a, n) for(ll i = n-1; i >= a; i--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, 0, n)
#define MD 1000000007

template<class T> T read(){T a;cin >> a;return a;}
template<class T> void read(T& a){cin >> a;}
template<class T> void rarr(T a, int n){for(int i = 0; i < n; i++) {cin >> a[i];}}
template<class T> void write(T a){cout << a << endl;}
template<class T> void writes(vector<T> a, const char* c = " "){cout << a[0];for(int i = 1; i < (int)a.size(); i++)cout << c << a[i];cout << endl;;}
void write(double a){cout << fixed << setprecision(12) << a << endl;}
void write(long double a){cout << fixed << setprecision(12) << a << endl;}
template<class T> void warr(T a, int n, const char* c = " "){cout << a[0];for(int i = 1; i < n; i++)cout << c << a[i];cout << endl;}
void split(string s, string delim, veci& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(atoi(s.substr(pos).data()));break;}else {result.push_back(atoi(s.substr(pos, p - pos).data()));}pos = p + delim.size();}}
void split(string s, string delim, vecs& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(s.substr(pos));break;}else {result.push_back(s.substr(pos, p - pos));}pos = p + delim.size();}}
ll gcd(ll a, ll b){while(true){ll k = a % b;if(k == 0)return b;a = b;b = k;}}
ll comb(ll n, ll m){ll p=1;m=min(m,n-m);for(ll i=1;i<=m;i++){p*=n-i+1;p/=i;}return p;}

int h,w,n;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int res[1000][1000]={0};
bool b[1000][1000][4]={0};
int xh[1000][1000]={0};
int yh[1000][1000]={0};

typedef pair<int,int> Vec;

Vec sp(int num){
    int x=num%w;
    int y=num/w;
    Vec p;
    p.first=x;p.second=h-y-1;
    return p;
}

int main(void)
{
    cin>>h>>w>>n;
    rep(i,h)rep(j,w)res[i][j]=-1;
    rep(i,n){
        int m=read<int>();
        Vec bef=sp(read<int>());
        rep(j,m){
            Vec p=sp(read<int>());
            if(p.second==bef.second){
                int x1=p.first;
                int x2=bef.first;
                if(x1>x2)swap(x1,x2);
                xh[p.second][x1]=max(xh[p.second][x1],x2);
            }
            else{
                int y1=p.second;
                int y2=bef.second;
                if(y1>y2)swap(y1,y2);
                yh[p.first][y1]=max(yh[p.first][y1],y2);
            }
            bef=p;
        }
    }
    rep(i,h){
        int j=0;
        while(j<w){
            if(xh[i][j]==0){
                j++;
                continue;
            }
            int p=xh[i][j];
            int sj=j;
            while(j<w&&j<=p){
                p=max(p,xh[i][j]);
                b[i][j][0]=b[i][j][2]=true;
                //cout<<j;
                j++;
            }
            //cout<<endl;
            b[i][sj][2]=false;
            b[i][j-1][0]=false;
        }
    }
    //cout<<endl;
    rep(i,w){
        int j=0;
        while(j<h){
            if(yh[i][j]==0){
                j++;
                continue;
            }
            int p=yh[i][j];
            int sj=j;
            while(j<h&&j<=p){
                //cout<<yh[i][j]<<" "<<p<<" ";
                p=max(p,yh[i][j]);
                b[j][i][1]=b[j][i][3]=true;
                j++;
            }
            //cout<<endl;
            b[sj][i][3]=false;
            b[j-1][i][1]=false;
        }
    }
    int sx=0,sy=h-1;
    queue<Vec> q;
    q.push(Vec(sx,sy));
    res[sy][sx]=0;
    while(!q.empty()){
        Vec top=q.front();
        int x=top.first;
        int y=top.second;
        q.pop();
        rep(i,4){
            if(!b[y][x][i])continue;
            int cx=x+dx[i];
            int cy=y+dy[i];
            if(res[cy][cx]>-1)continue;
            res[cy][cx]=res[y][x]+1;
            q.push(Vec(cx,cy));
        }
    }
    if(res[0][w-1]!=-1)
        write(res[0][w-1]);
    else 
        write("Odekakedekinai..");
    return 0;
}
0