結果
| 問題 | 
                            No.340 雪の足跡
                             | 
                    
| コンテスト | |
| ユーザー | 
                             kyuridenamida
                         | 
                    
| 提出日時 | 2016-01-29 22:47:40 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 2,724 bytes | 
| コンパイル時間 | 888 ms | 
| コンパイル使用メモリ | 97,624 KB | 
| 実行使用メモリ | 23,296 KB | 
| 最終ジャッジ日時 | 2024-09-21 18:24:44 | 
| 合計ジャッジ時間 | 19,794 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 23 TLE * 9 | 
ソースコード
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <ctime>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>
#include <fstream>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <numeric>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rev(i,n) for(int i=(n)-1;(i)>=0;(i)--)
#define all(a) (a).begin(),(a).end()
#define pb(a) push_back(a)
#define bitcount(b) __builtin_popcount(b)
template<typename T, typename S> vector<T>& operator<<(vector<T>& a, S b) { a.push_back(b); return a; }
template<typename T> void operator>>(vector<T>& a, int b) {while(b--)if(!a.empty())a.pop_back();}
bool isprime(int n){ if(n<2)return false;  for(int i=2;i*i<=n;i++)if(n%i==0)return false;  return true;} 
ll b_pow(ll x,ll n){return n ? b_pow(x*x,n/2)*(n%2?x:1) : 1ll;}
string itos(int n){stringstream ss;ss << n;return ss.str();}
template<class T> ostream& operator<<(ostream& os, const pair<T,T>& p)
{
	os << "(" << p.first << "," << p.second << ")";
    return os;
}
template<class T> ostream& operator<<(ostream& os, const vector<T>& arr)
{
	os << "{";
	for(int i = 0 ; i < arr.size() ; i++) os << (i==0?"":",") << arr[i];
	os << "}";
    return os;
}
int dx[] = {-1,0,1,0};
int dy[] = {0,1,0,-1};
int dir(int x,int y,int x2,int y2){
	if( x == x2 ){
		if( y < y2 ) return 1;
		else return 3;
	}else{
		if( x < x2 ) return 2;
		else return 0;
	}
}
int color[1010][1010][4];
struct NODE{
	int x,y,c;
};
int dn[1010][1010];
int main(){
	int W,H,N;
	cin >> W >> H >> N;
	if( W * H == 1 ){
		cout << 0 << endl;
		return 0;
	}
	
	for(int i = 0 ; i < N ; i++){
		int M;
		cin >> M;
		int px,py;
		for(int j = 0 ; j <= M ; j++){
			int w;
			cin >> w;
			int x = w % W;
			int y = w / W;
			// cout << x << " " << y << endl;
			if(j){
				int dd = dir(px,py,x,y);
				int c = abs(x-px) + abs(y-py);
				int cx = px;
				int cy = py;
				while(c--){
					color[cy][cx][dd] = true;
					cx += dx[dd];
					cy += dy[dd];
					color[cy][cx][(dd+2)%4] = true;
				}
			}
			px = x;
			py = y;
		}
	}
	queue<NODE> Q;
	Q.push({0,0,0});
	while( Q.size() ){
		auto q = Q.front(); Q.pop();
		if( q.y < 0 || q.x >= W || q.y >= H || q.y < 0 ) continue;
		if( dn[q.y][q.x]++ ) continue;
		if( q.y == H-1 && q.x == W - 1 ){
			cout << q.c << endl;
			return 0;
		}
		for(int i = 0 ; i < 4 ; i++){
			if( color[q.y][q.x][i] )
				Q.push({q.x+dx[i],q.y+dy[i],q.c+1});
		}
	
		
	}
	cout << "Odekakedekinai.." << endl;
	
}
            
            
            
        
            
kyuridenamida