Submission #1013116

#TimeUsernameProblemLanguageResultExecution timeMemory
1013116vjudge1Slagalica (COCI19_slagalica2)C++17
35 / 70
49 ms3484 KiB
#include <bits/stdc++.h> using namespace std; vector<int> rc[9]; vector<int> val[9]; int en; pair<int,int> opt(int x) { pair<int,int> ans={1e9+1,-1}; for (int t:rc[x]) { if (val[t].empty()) continue; if (t<=4) { if (t==2 || t==3 || !val[5-t].empty()) { if (ans.first>val[t].back()) ans.first=val[t].back(),ans.second=t; } } } if (ans.second==-1) { for (int t:rc[x]) { if (val[t].empty()) continue; if (t<=4) ans.first=val[t].back(),ans.second=t; } if (ans.second==-1) { for (int t:rc[x]) { if (!val[t].empty()) ans.first=val[t].back(),ans.second=t; } if (ans.second==-1) return ans; } } val[ans.second].pop_back(); return ans; } int main() { rc[1]={3,4,8}; rc[2]={1,2,7}; rc[3]={3,4,8}; rc[4]={1,2,7}; rc[5]={3,4,8}; rc[6]={1,2,7}; rc[7]={7}; rc[8]={8}; int n,st,oo; cin>>n; for (int i=0;i<n;i++) { int t,a; cin>>t>>a; val[t].push_back(a); if (t==6 || t==5) st=t,oo=a; else if(t==7 || t==8) en=t; } for (int i=0;i<9;i++) sort(val[i].begin(),val[i].end(),greater<int>()); vector<int> ans={oo}; bool b=0; while (1) { auto p=opt(st); if (p.second==-1) break; ans.push_back(p.first),st=p.second; if (st==en) b=1; } if (!b) cout<<-1<<endl; else for (int i:ans) cout<<i<<' '; return 0; }

Compilation message (stderr)

slagalica.cpp: In function 'int main()':
slagalica.cpp:59:11: warning: 'oo' may be used uninitialized in this function [-Wmaybe-uninitialized]
   59 |  int n,st,oo;
      |           ^~
slagalica.cpp:77:16: warning: 'st' may be used uninitialized in this function [-Wmaybe-uninitialized]
   77 |   auto p=opt(st);
      |                ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...