Submission #711690

#TimeUsernameProblemLanguageResultExecution timeMemory
711690minipigSlagalica (COCI19_slagalica2)C++14
20 / 70
41 ms3008 KiB
#include <bits/stdc++.h> using namespace std; int block_type[9][2]={{0,0},{1,1},{1,-1},{-1,1},{-1,-1},{0,1},{0,-1},{1,0},{-1,0}}; vector<int> block[9]; int pos[9]; vector<int> ans; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n; int left_bump=0,left_hole=0,right_bump=0,right_hole=0,start_type,end_type; for(int i=0;i<n;i++){ int type,number; cin>>type>>number; if(type==5){ start_type=5; } else if(type==6){ start_type=6; } else if(type==7){ end_type=7; } else{ end_type=8; } if(block_type[type][0]==1){ left_bump++; } else if(block_type[type][0]==-1){ left_hole++; } if(block_type[type][1]==1){ right_bump++; } else if(block_type[type][1]==-1){ right_hole++; } block[type].push_back(number); } for(int i=1;i<9;i++){ sort(block[i].begin(),block[i].end()); } if(left_bump!=right_hole||right_bump!=left_hole){ cout<<"-1\n"; return 0; } ans.push_back(block[start_type][0]); if(start_type==5){ right_bump--; } else{ right_hole--; } pos[start_type]++; int now=start_type; for(int i=0;i<n-1;i++){ int next_type; int idx=-1; for(int j=1;j<=8;j++){ if(block_type[now][1]+block_type[j][0]==0&&pos[j]!=block[j].size()){ if(idx==-1||block[idx][pos[j]]>block[j][pos[j]]){ if(!(i!=n-3&&((block_type[j][1]==1&&left_hole==1&&end_type==8)||(block_type[j][1]==-1&&left_bump==1&&end_type==7)))){ idx=j; } } } } if(idx==-1){ cout<<"-1\n"; return 0; } ans.push_back(block[idx][pos[idx]]); pos[idx]++; if(block_type[idx][0]==1){ left_bump--; } else if(block_type[idx][0]==-1){ left_hole--; } if(block_type[idx][1]==1){ right_bump--; } else if(block_type[idx][1]==-1){ right_hole--; } now=idx; } for(int i=0;i<n;i++){ cout<<ans[i]<<" \n"[i==n-1]; } return 0; }

Compilation message (stderr)

slagalica.cpp: In function 'int main()':
slagalica.cpp:66:62: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |             if(block_type[now][1]+block_type[j][0]==0&&pos[j]!=block[j].size()){
      |                                                        ~~~~~~^~~~~~~~~~~~~~~~~
slagalica.cpp:63:13: warning: unused variable 'next_type' [-Wunused-variable]
   63 |         int next_type;
      |             ^~~~~~~~~
slagalica.cpp:68:130: warning: 'end_type' may be used uninitialized in this function [-Wmaybe-uninitialized]
   68 |                     if(!(i!=n-3&&((block_type[j][1]==1&&left_hole==1&&end_type==8)||(block_type[j][1]==-1&&left_bump==1&&end_type==7)))){
      |                                                                                                                          ~~~~~~~~^~~
slagalica.cpp:60:19: warning: 'start_type' may be used uninitialized in this function [-Wmaybe-uninitialized]
   60 |     pos[start_type]++;
      |     ~~~~~~~~~~~~~~^
#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...