結果

問題 No.340 雪の足跡
ユーザー kyuridenamidakyuridenamida
提出日時 2016-01-29 22:59:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 314 ms / 1,000 ms
コード長 3,395 bytes
コンパイル時間 954 ms
コンパイル使用メモリ 103,444 KB
実行使用メモリ 23,792 KB
最終ジャッジ日時 2023-10-21 17:17:30
合計ジャッジ時間 5,998 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
21,084 KB
testcase_01 AC 18 ms
21,088 KB
testcase_02 AC 18 ms
19,640 KB
testcase_03 AC 18 ms
21,084 KB
testcase_04 AC 17 ms
21,076 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 18 ms
21,084 KB
testcase_07 AC 17 ms
21,076 KB
testcase_08 AC 17 ms
21,092 KB
testcase_09 AC 17 ms
21,076 KB
testcase_10 AC 17 ms
21,092 KB
testcase_11 AC 19 ms
21,228 KB
testcase_12 AC 18 ms
21,224 KB
testcase_13 AC 18 ms
21,360 KB
testcase_14 AC 29 ms
22,052 KB
testcase_15 AC 32 ms
22,228 KB
testcase_16 AC 28 ms
21,792 KB
testcase_17 AC 36 ms
22,260 KB
testcase_18 AC 33 ms
22,260 KB
testcase_19 AC 37 ms
22,260 KB
testcase_20 AC 150 ms
23,784 KB
testcase_21 AC 116 ms
21,080 KB
testcase_22 AC 17 ms
19,640 KB
testcase_23 AC 166 ms
23,784 KB
testcase_24 AC 136 ms
23,784 KB
testcase_25 AC 145 ms
23,044 KB
testcase_26 AC 43 ms
21,972 KB
testcase_27 AC 22 ms
21,092 KB
testcase_28 AC 41 ms
22,020 KB
testcase_29 AC 268 ms
23,788 KB
testcase_30 AC 184 ms
23,148 KB
testcase_31 AC 274 ms
23,792 KB
testcase_32 AC 314 ms
23,792 KB
testcase_33 AC 248 ms
23,792 KB
testcase_34 AC 314 ms
23,792 KB
testcase_35 AC 182 ms
23,792 KB
testcase_36 AC 180 ms
23,792 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:89:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   89 |                         scanf("%d",&w);
      |                         ~~~~~^~~~~~~~~

ソースコード

diff #

#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 <unordered_set>
#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,pw;
		for(int j = 0 ; j <= M ; j++){
			int w;
			scanf("%d",&w);
			
			pw = 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 fx = px;
				int fy = py;
				int tx = x;
				int ty = y;
				if( dd == 0 || dd == 3 ){
					swap(fx,tx);
					swap(fy,ty);
					dd += 2;
					dd %= 4;
				}
				color[fy][fx][dd] += 1;
				color[ty][tx][dd] += -1;
				if( dd == 1 ) {
					fy++;
					ty++;
				}else{
					fx++;
					tx++;
				}
				color[fy][fx][(dd+2)%4] += 1;
				color[ty][tx][(dd+2)%4] += -1;
			}
			px = x;
			py = y;
		}
	}
	for(int d = 0 ; d < 4 ; d++){
		if( d == 0 || d == 2 ){
			for(int i = 0 ; i < 1010 ; i++){
				for(int j = 1 ; j < 1010 ; j++){
					color[i][j][d] += color[i][j-1][d];
				}
			}
		}else{
			for(int i = 0 ; i < 1010 ; i++){
				for(int j = 1 ; j < 1010 ; j++){
					color[j][i][d] += color[j-1][i][d];
				}
			}
		}
	}
	queue<NODE> Q;
	Q.push({0,0,0});
	dn[0][0] = 1;
	while( Q.size() ){
		auto q = Q.front(); Q.pop();
		if( q.y < 0 || q.x >= W || q.y >= H || q.y < 0 ) 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] ){
				NODE t = {q.x+dx[i],q.y+dy[i],q.c+1};
				if( t.y < 0 || t.x >= W || t.y >= H || t.y < 0 || dn[t.y][t.x]++ ) continue;
				Q.push(t);
			}
		}
	
		
	}
	cout << "Odekakedekinai.." << endl;
	
}
0