結果
問題 | No.1647 Travel in Mitaru city 2 |
ユーザー | yunix91201367 |
提出日時 | 2021-08-13 23:14:36 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,724 bytes |
コンパイル時間 | 2,411 ms |
コンパイル使用メモリ | 196,068 KB |
実行使用メモリ | 21,832 KB |
最終ジャッジ日時 | 2024-10-03 22:56:59 |
合計ジャッジ時間 | 15,488 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 4 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 8 ms
6,816 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 202 ms
20,952 KB |
testcase_11 | AC | 114 ms
15,744 KB |
testcase_12 | WA | - |
testcase_13 | AC | 102 ms
14,592 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 185 ms
20,320 KB |
testcase_17 | AC | 118 ms
15,744 KB |
testcase_18 | WA | - |
testcase_19 | AC | 142 ms
17,664 KB |
testcase_20 | WA | - |
testcase_21 | AC | 181 ms
19,840 KB |
testcase_22 | AC | 209 ms
21,708 KB |
testcase_23 | AC | 213 ms
21,828 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | AC | 218 ms
21,680 KB |
testcase_28 | AC | 220 ms
21,636 KB |
testcase_29 | AC | 218 ms
21,636 KB |
testcase_30 | AC | 184 ms
20,056 KB |
testcase_31 | AC | 220 ms
21,632 KB |
testcase_32 | WA | - |
testcase_33 | AC | 177 ms
19,964 KB |
testcase_34 | AC | 223 ms
21,636 KB |
testcase_35 | WA | - |
testcase_36 | AC | 223 ms
21,632 KB |
testcase_37 | AC | 220 ms
21,748 KB |
testcase_38 | WA | - |
testcase_39 | AC | 165 ms
19,328 KB |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | AC | 2 ms
5,248 KB |
testcase_44 | AC | 6 ms
7,936 KB |
testcase_45 | AC | 92 ms
14,632 KB |
testcase_46 | AC | 125 ms
14,720 KB |
testcase_47 | AC | 91 ms
14,592 KB |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | AC | 91 ms
14,720 KB |
ソースコード
#include <bits/stdc++.h> #include <atcoder/math> using namespace std; using namespace atcoder; #define int long long using vec_int = vector<int>; using vec_ii = vector<vec_int>; using vec_iii = vector<vec_ii>; using vec_iiii = vector<vec_iii>; using P = pair<int,int>; using T = tuple<int,int,int>; using ll = long long; using ld = long double; #define rep(i, n) for(int i = 0; i < (int)(n); i++) void cout_line(vector<int> &a){ for(int i=0;i<a.size();i++){ if(i<a.size()-1){ cout<<a.at(i)<<" "; }else{ cout<<a.at(i)<<endl; } } } int charToInt(char c){ char zero_num = '0'; return (int)c - (int)zero_num; } signed main(){ int H, W, N; cin>>H>>W>>N; vec_int x(N), y(N); rep(i,N)cin>>x.at(i)>>y.at(i); vector<vec_int> x_city(H+1); vector<vec_int> y_city(W+1); rep(i, N){ x_city.at(x.at(i)).push_back(i); y_city.at(y.at(i)).push_back(i); } vec_int visited(N+1, -2); queue<T> que; for(int i=0;i<N;i++){ if(visited.at(i)==-2){ que.emplace(i, 0, -1); que.emplace(i, 1, -1); }else{ continue; } int flag = 0; int pos1, pos2; map<int,int> visited_map; while(!que.empty()){ int pos, direc, prev; tie(pos, direc, prev) = que.front(); que.pop(); //cout<<"pos:"<<pos<<" "<<direc<<endl; if(visited_map.count(pos)){ if(visited_map[pos]>=-1&&prev>=0){ pos1 = pos; pos2 = prev; flag = 1; break; } } visited_map[pos] = prev; if(direc==0){ for(auto next: x_city.at(x.at(pos))){ if(next==pos)continue; if(visited.at(next)>0)continue; que.emplace(next, 1, pos); } }else{ for(auto next: y_city.at(y.at(pos))){ if(next==pos)continue; if(visited.at(next)>0)continue; que.emplace(next, 0, pos); } } } if(flag==0){ for(auto temp:visited_map){ visited.at(temp.first) = 1; } continue; } vec_int route1, route2; while(pos1>=0){ route1.push_back(pos1); pos1 = visited_map[pos1]; } reverse(route1.begin(), route1.end()); while(pos2>=0){ route2.push_back(pos2); pos2 = visited_map[pos2]; } reverse(route2.begin(), route2.end()); int ind = 0; for(int i=0;i<route1.size()&&i<route2.size();i++){ if(route1.at(i)!=route2.at(i))break; ind = i+1; } vec_int ans; for(int i=ind;i<route1.size();i++){ ans.push_back(route1.at(i)+1); } reverse(ans.begin(), ans.end()); /* ans.push_back(route1.at(ind-1)+1); */ int pos0 = route1.at(ind-1); int poss1 = route1.at(ind); int poss2 = route2.at(ind); int flag1, flag2; if(x.at(poss1)==x.at(pos0)){ flag1 = 0; }else{ flag1 = 1; } if(x.at(poss2)==x.at(pos0)){ flag2 = 0; }else{ flag2 = 1; } if(flag1!=flag2){ ans.push_back(route1.at(ind-1)+1); } for(int i=ind;i<route2.size();i++){ ans.push_back(route2.at(i)+1); } cout<<ans.size()<<endl; cout_line(ans); return 0; } cout<<-1<<endl; return 0; }