結果
問題 | No.340 雪の足跡 |
ユーザー | koyumeishi |
提出日時 | 2016-01-29 23:41:55 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 347 ms / 1,000 ms |
コード長 | 2,776 bytes |
コンパイル時間 | 980 ms |
コンパイル使用メモリ | 99,656 KB |
実行使用メモリ | 27,008 KB |
最終ジャッジ日時 | 2024-09-21 18:48:32 |
合計ジャッジ時間 | 5,957 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | AC | 1 ms
5,376 KB |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 3 ms
5,376 KB |
testcase_14 | AC | 13 ms
5,376 KB |
testcase_15 | AC | 16 ms
5,376 KB |
testcase_16 | AC | 11 ms
5,376 KB |
testcase_17 | AC | 20 ms
5,376 KB |
testcase_18 | AC | 17 ms
5,376 KB |
testcase_19 | AC | 20 ms
5,504 KB |
testcase_20 | AC | 182 ms
27,008 KB |
testcase_21 | AC | 104 ms
5,376 KB |
testcase_22 | AC | 42 ms
26,752 KB |
testcase_23 | AC | 206 ms
27,008 KB |
testcase_24 | AC | 165 ms
26,752 KB |
testcase_25 | AC | 173 ms
26,880 KB |
testcase_26 | AC | 26 ms
5,376 KB |
testcase_27 | AC | 7 ms
5,376 KB |
testcase_28 | AC | 24 ms
5,376 KB |
testcase_29 | AC | 248 ms
16,896 KB |
testcase_30 | AC | 162 ms
13,824 KB |
testcase_31 | AC | 296 ms
24,960 KB |
testcase_32 | AC | 347 ms
27,008 KB |
testcase_33 | AC | 286 ms
27,008 KB |
testcase_34 | AC | 346 ms
26,880 KB |
testcase_35 | AC | 235 ms
27,008 KB |
testcase_36 | AC | 231 ms
26,880 KB |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:30:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 30 | scanf("%d", &m); | ~~~~~^~~~~~~~~~ main.cpp:32:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 32 | scanf("%d", &pos); | ~~~~~^~~~~~~~~~~~ main.cpp:35:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 35 | scanf("%d", &next); | ~~~~~^~~~~~~~~~~~~
ソースコード
#include <iostream> #include <vector> #include <cstdio> #include <sstream> #include <map> #include <string> #include <algorithm> #include <queue> #include <cmath> #include <functional> #include <set> #include <ctime> #include <random> using namespace std; template<class T> istream& operator >> (istream& is, vector<T>& vec){for(T& val: vec) is >> val; return is;} template<class T> istream& operator , (istream& is, T& val){ return is >> val;} template<class T> ostream& operator << (ostream& os, vector<T>& vec){for(int i=0; i<vec.size(); i++) os << vec[i] << (i==vec.size()-1?"\n":" ");return os;} template<class T> ostream& operator , (ostream& os, T& val){ return os << " " << val;} template<class T> ostream& operator >> (ostream& os, T& val){ return os << " " << val;} int main(){ int w,h,n; cin >> w,h,n; vector<vector<int>> tate(2*h+1, vector<int>(w+1, 0)); vector<vector<int>> yoko(h+1, vector<int>(2*w+1, 0)); for(int i=0; i<n; i++){ int m; scanf("%d", &m); int pos; scanf("%d", &pos); while(m--){ int next; scanf("%d", &next); if(next%w == pos%w){ // tate int c = next%w; tate[2*min(pos/w, next/w)][c]++; tate[2*max(pos/w, next/w)+1][c]--; }else{ // yoko int r = next/w; yoko[r][2*min(pos%w, next%w)]++; yoko[r][2*max(pos%w, next%w)+1]--; } pos = next; } } for(int i=0; i<h; i++){ int val = 0; for(int j=0; j<yoko[i].size(); j++){ val += yoko[i][j]; yoko[i][j] = val>0; } } for(int j=0; j<w; j++){ int val = 0; for(int i=0; i<tate.size(); i++){ val += tate[i][j]; tate[i][j] = val>0; } } vector<vector<int>> dist(h+1, vector<int>(w+1, 10000000)); vector<int> in_queue(h*w, 0); dist[0][0] = 0; vector<int> dx = {0,0,1,-1}; vector<int> dy = {1,-1,0,0}; queue<pair<int,int>> q; auto my_push = [&](int y, int x){ if(in_queue[ x + y*w ]) return; in_queue[ x+y*w ] = 1; q.push({y,x}); }; auto my_pop = [&](){ auto ret = q.front(); q.pop(); in_queue[ ret.first*w + ret.second ] = 0; return ret; }; my_push(0,0); while(q.size()){ auto pos = my_pop(); int x = pos.second; int y = pos.first; for(int k__=0; k__<4; k__++){ int new_x = x + dx[k__]; int new_y = y + dy[k__]; if(new_x < 0 || new_x >= w || new_y < 0 || new_y >= h) continue; if(x==new_x){ if(tate[y+new_y][x]){ if(dist[new_y][new_x] > dist[y][x] + 1){ dist[new_y][new_x] = dist[y][x]+1; my_push(new_y, new_x); } } }else if(y==new_y){ if(yoko[y][x+new_x]){ if(dist[new_y][new_x] > dist[y][x] + 1){ dist[new_y][new_x] = dist[y][x]+1; my_push(new_y, new_x); } } } } } if(dist[h-1][w-1] != 10000000){ cout << dist[h-1][w-1] << endl; }else{ cout << "Odekakedekinai.." << endl; } return 0; }