Submission #711649

#TimeUsernameProblemLanguageResultExecution timeMemory
711649guagua0407Slagalica (COCI19_slagalica2)C++17
15 / 70
28 ms2124 KiB
//#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define f first #define s second #define all(x) x.begin(),x.end() #define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } int main() {_ int n; cin>>n; vector<int> num[9]; vector<int> adj[9]; vector<int> sz(9,0); for(int i=0;i<n;i++){ int a,b; cin>>a>>b; num[a].push_back(b); sz[a]++; } for(int i=1;i<9;i++){ sort(num[i].rbegin(),num[i].rend()); } adj[1].push_back(3); adj[1].push_back(4); adj[1].push_back(8); adj[3].push_back(3); adj[3].push_back(4); adj[3].push_back(8); adj[5].push_back(3); adj[5].push_back(4); adj[5].push_back(8); adj[2].push_back(1); adj[2].push_back(2); adj[2].push_back(7); adj[4].push_back(1); adj[4].push_back(2); adj[4].push_back(7); adj[6].push_back(1); adj[6].push_back(2); adj[6].push_back(7); int cur=(sz[5]>0?5:6); vector<int> ans; ans.push_back(num[cur].back()); num[cur].pop_back(); sz[cur]--; for(int i=0;i<n-2;i++){ //cout<<cur<<'\n'; int mn=1e9+1; int tt; for(auto v:adj[cur]){ //cout<<v<<' '<<sz[v]<<'\n'; if(sz[v]==0) continue; sz[v]--; bool tf=false; for(auto u:adj[v]){ if(i!=n-3 and (u==7 or u==8)) continue; if(sz[u]>0){ tf=true; break; } } sz[v]++; if(tf){ if(num[v].back()<mn){ mn=num[v].back(); tt=v; } } } if(mn==1e9+1){ cout<<-1; return 0; } sz[tt]--; ans.push_back(num[tt].back()); num[tt].pop_back(); cur=tt; } int target=(sz[7]>0?7:8); bool tf=false; for(auto v:adj[cur]){ if(v==target){ tf=true; break; } } if(!tf){ cout<<-1; return 0; } ans.push_back(num[target].back()); for(auto v:ans){ cout<<v<<' '; } return 0; } //maybe its multiset not set

Compilation message (stderr)

slagalica.cpp: In function 'void setIO(std::string)':
slagalica.cpp:12:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
slagalica.cpp:13:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...