結果
問題 | No.1612 I hate Construct a Palindrome |
ユーザー | momoyuu |
提出日時 | 2024-08-09 18:33:40 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,322 bytes |
コンパイル時間 | 1,786 ms |
コンパイル使用メモリ | 128,780 KB |
実行使用メモリ | 23,688 KB |
最終ジャッジ日時 | 2024-08-09 18:33:50 |
合計ジャッジ時間 | 8,781 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 4 ms
5,376 KB |
testcase_02 | AC | 292 ms
23,688 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 5 ms
5,376 KB |
testcase_05 | AC | 292 ms
23,688 KB |
testcase_06 | AC | 86 ms
14,208 KB |
testcase_07 | AC | 116 ms
13,824 KB |
testcase_08 | AC | 113 ms
17,024 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | AC | 2 ms
5,376 KB |
testcase_28 | AC | 2 ms
5,376 KB |
testcase_29 | AC | 2 ms
5,376 KB |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | AC | 2 ms
5,376 KB |
testcase_37 | WA | - |
testcase_38 | WA | - |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:126:30: warning: 'nj' may be used uninitialized [-Wmaybe-uninitialized] 126 | ans.push_back(g[0][nj].second.second); | ^ main.cpp:118:13: note: 'nj' was declared here 118 | int nj; | ^~ main.cpp:131:29: warning: 'wu' may be used uninitialized [-Wmaybe-uninitialized] 131 | for(int i = 0;i<g[wu].size();i++){ | ^ main.cpp:82:9: note: 'wu' was declared here 82 | int wu,ni; | ^~ main.cpp:40:51: warning: 'nj' may be used uninitialized [-Wmaybe-uninitialized] 40 | cout<<g[0][0].second.second<<endl<<g[0][nj].second.second<<endl<<g[0][nj].second.second<<endl; | ^ main.cpp:33:20: note: 'nj' was declared here 33 | int ni = 0,nj; | ^~
ソースコード
#include<iostream> #include<vector> #include<algorithm> using namespace std; using ll = long long; #include<set> int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n,m; cin>>n>>m; vector<vector<pair<int,pair<char,int>>>> g(n); vector<char> C(m); set<char> s; for(int i = 0;i<m;i++){ int u,v; char c; cin>>u>>v>>c; C[i] = c; u--;v--; s.insert(c); g[u].push_back({v,{c,i+1}}); g[v].push_back({u,{c,i+1}}); } if(s.size()==1){ cout<<-1<<endl; return 0; } if(n==2){ int ni = 0,nj; for(int i = 0;i<g[0].size();i++){ if(g[0][0].second.first==g[0][i].second.first) continue; nj = i; break; } cout<<3<<endl; cout<<g[0][0].second.second<<endl<<g[0][nj].second.second<<endl<<g[0][nj].second.second<<endl; return 0; }else if(n==3){ vector<int> ans; for(int i = 0;i<3;i++){ set<int> a; set<char> b; vector<int> use; for(int j = 0;j<g[i].size();j++){ if(b.find(g[i][j].second.first)!=b.end()) continue; if(a.find(g[i][j].first)!=a.end()) continue; b.insert(g[i][j].second.first); a.insert(g[i][j].first); use.push_back(j); } if(a.size()<2) continue; int ni = use[0]; int nj = use[1]; if(i==0){ if(g[0][ni].first==2) swap(ni,nj); ans.push_back(g[0][ni].second.second); ans.push_back(g[0][ni].second.second); ans.push_back(g[0][nj].second.second); break; }else if(i==1){ if(g[i][ni].first==2) swap(ni,nj); ans.push_back(g[0][ni].second.second); ans.push_back(g[0][nj].second.second); break; }else{ if(g[i][ni].first==1) swap(ni,nj); ans.push_back(g[0][ni].second.second); ans.push_back(g[0][nj].second.second); ans.push_back(g[0][nj].second.second); break; } } cout<<ans.size()<<endl; for(int i = 0;i<ans.size();i++) cout<<ans[i]<<endl; return 0; } char no = g[n-1][0].second.first; int wu,ni; ni = -1; int wv; for(int i = 0;i<n;i++){ set<char> now; for(auto itr:g[i]){ now.insert(itr.second.first); } if(now.size()==1) continue; wu = i; break; } vector<int> vis(n,0); bool fn = false; vector<int> que; auto dfs = [&](auto dfs,int ni,int to) -> void { vis[ni]++; if(ni==to){ fn = true; return; } for(auto&itr:g[ni]){ int nj = itr.first; if(vis[nj]) continue; que.push_back(itr.second.second); dfs(dfs,nj,to); if(fn) return; que.pop_back(); } }; dfs(dfs,0,wu); vector<int> ans = que; que.clear(); int k = wu; if(wu==0){ int ni = 0; int nj; for(int j = 1;j<g[0].size();j++){ if(g[0][j].second.first!=g[0][0].second.first){ nj = j; break; } } ans.push_back(g[0][ni].second.second); ans.push_back(g[0][nj].second.second); ans.push_back(g[0][nj].second.second); k = g[0][nj].first; }else{ int ni = ans.back(); for(int i = 0;i<g[wu].size();i++){ if(g[wu][i].second.first==C[ni]) continue; ans.push_back(g[wu][i].second.second); k = g[wu][i].first; break; } } for(int i = 0;i<n;i++) vis[i] = 0; int from = k; int to = n - 1; fn = false; dfs(dfs,from,to); for(int i:que) ans.push_back(i); string use; for(int i = 0;i<ans.size();i++){ use += C[ans[i]-1]; } string u = use; reverse(u.begin(),u.end()); if(use==u){ ans.push_back(g[n-1][0].second.second); ans.push_back(g[n-1][0].second.second); } cout<<ans.size()<<endl; for(int i = 0;i<ans.size();i++) cout<<ans[i]<<endl; }