結果
問題 | No.1647 Travel in Mitaru city 2 |
ユーザー | yunix91201367 |
提出日時 | 2021-08-13 23:06:23 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,278 bytes |
コンパイル時間 | 2,499 ms |
コンパイル使用メモリ | 195,360 KB |
実行使用メモリ | 21,760 KB |
最終ジャッジ日時 | 2024-10-03 22:28:49 |
合計ジャッジ時間 | 17,287 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,820 KB |
testcase_04 | AC | 4 ms
6,820 KB |
testcase_05 | AC | 2 ms
6,820 KB |
testcase_06 | AC | 2 ms
6,820 KB |
testcase_07 | AC | 8 ms
6,912 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 223 ms
20,948 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 98 ms
14,592 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 199 ms
20,320 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 237 ms
21,708 KB |
testcase_23 | AC | 229 ms
21,700 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | AC | 226 ms
21,680 KB |
testcase_28 | AC | 239 ms
21,632 KB |
testcase_29 | AC | 228 ms
21,760 KB |
testcase_30 | WA | - |
testcase_31 | AC | 235 ms
21,628 KB |
testcase_32 | WA | - |
testcase_33 | AC | 194 ms
19,968 KB |
testcase_34 | AC | 236 ms
21,548 KB |
testcase_35 | WA | - |
testcase_36 | AC | 260 ms
21,632 KB |
testcase_37 | AC | 243 ms
21,632 KB |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | AC | 2 ms
6,820 KB |
testcase_44 | AC | 5 ms
8,016 KB |
testcase_45 | WA | - |
testcase_46 | AC | 139 ms
14,720 KB |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | WA | - |
ソースコード
#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); 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; }