Submission #265003

#TimeUsernameProblemLanguageResultExecution timeMemory
265003sonvip9Slagalica (COCI19_slagalica2)C++14
0 / 70
1096 ms4844 KiB
#include<bits/stdc++.h> #define ii pair<int,int> #define fi first #define se second #define ll long long #define BIT(x,k) ((x>>k)&1) #define db double #define pb push_back #define turnoff(t,k) (t^(1<<(k))) #define getbit(k,x) ((x>>k)&1) #define FOR(i,x,y) for(int i=x;i<=y;i++) #define ROF(i,x,y) for(int i=x;i>=y;i--) using namespace std; int n; vector<int> hack; ii puz[100010]; int kq[100010]; int x[100010]; int a[100010]; int kind[100010]; int endless=0; bool have=false; int zz[100010],d[100010]; ll res=1e18; priority_queue<int> qu[10]; void ghinghiem() { bool check1=false; bool check2=false; bool check3=false; bool check4=false; int tgg=0; // for(int i=1; i<=n; i++) // { // cout<<zz[i]<<" "; // } // cout<<"\n"; for(int i=1; i<=n; i++) { // cout<<zz[i]<<"\n"; // if(x[zz[1]]==5) // { // cout<<"yeah\n"; // } // cout<<i<<"\n"; if(i==1 and x[zz[i]]!=5 and x[zz[i]]!=6) { return; } else { if(x[zz[i]]==5) { check1=false; check2=false; check3=true; check4=true; continue; } if(x[zz[i]]==6) { check4=false; check3=false; check2=true; check1=true; continue; } } if(i==n and x[zz[i]]!=7 and x[zz[i]]!=8) { return; } else { if(x[zz[i]]==7 and tgg!=0) { return; } if(x[zz[i]]==8 and tgg!=1) { return; } } if(x[zz[i]]==1) { if(check1==true) { tgg=1; check1=false; check2=false; check3=true; check4=true; } else { return; } } if(x[zz[i]]==2) { if(check2==true) { tgg=0; check4=false; check3=false; check2=true; check1=true; } else { return; } } if(x[zz[i]]==3) { if(check3==true) { tgg=1; check1=false; check2=false; check3=true; check4=true; } else { return; } } if(x[zz[i]]==4) { if(check4==true) { tgg=0; check4=false; check3=false; check2=true; check1=true; } else { return; } } } have=true; ll _res=0; for(int i=1; i<=n; i++) { _res=_res*10+a[zz[i]]; } res=min(res,_res); } void blackk(int i) { for(int j=1; j<=n; j++) if(d[j]==0) { zz[i]=j; d[j]=1; if(i==n) ghinghiem(); else blackk(i+1); d[j]=0; } } void io() { freopen("Slagalica.inp","r",stdin); freopen("Slagalica.out","w",stdout); } void inp() { cin>>n; for(int i=1; i<=n; i++) { cin>>x[i]>>a[i]; qu[x[i]].push(-a[i]); if(x[i]==7 or x[i]==8) { endless=a[i]; } } } void proc1() { blackk(1); if(!have) {cout<<"-1";exit(0);} else { while(res>0) { hack.pb(res%10); res/=10; } for(int i=hack.size()-1;i>=0;i--) { cout<<hack[i]<<" "; } } } void proc3() { if(!qu[5].empty()) kind[1]=1; else kind[1]=0; bool check=true; for(int i=2; i<n; i++) { if(kind[i-1]==1) { if(!qu[4].empty()) { kq[i]=-qu[4].top(); qu[4].pop(); } else { check=false; break; } kind[i]=0; } if(kind[i]=0) { if(!qu[1].empty()) { kq[i]=-qu[1].top(); qu[1].pop(); } else { check=false; break; } kind[i]=1; } } if(check==false) { cout<<"-1"; return; } else { if(kind[n-1]==1 and !qu[7].empty()) { cout<<"-1"; return; } if(kind[n-1]==0 and !qu[8].empty()) { cout<<"-1"; return; } for(int i=1; i<=n-1; i++) { cout<<kq[i]<<" "; } } } int main() { //io(); inp(); proc1(); return 0; }

Compilation message (stderr)

slagalica.cpp: In function 'void proc3()':
slagalica.cpp:227:19: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
  227 |         if(kind[i]=0)
      |            ~~~~~~~^~
slagalica.cpp: In function 'void io()':
slagalica.cpp:170:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  170 |     freopen("Slagalica.inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
slagalica.cpp:171:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  171 |     freopen("Slagalica.out","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...