Submission #782167

#TimeUsernameProblemLanguageResultExecution timeMemory
782167amirhoseinfar1385Watermelon (INOI20_watermelon)C++17
31 / 100
12 ms2760 KiB
#include<bits/stdc++.h> using namespace std; int n,m; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>m; vector<int>all(n); for(int i=0;i<n;i++){ cin>>all[i]; } vector<int>res(n+1); vector<int>allv; for(int i=0;i<n;i++){ if(all[i]==-1){ allv.push_back(i); } } int now=n; for(int i=0;i<(int)allv.size();i++){ res[allv[i]]=now; now--; } now=1; int last=-1; vector<int>st; for(int j=0;j<n;j++){ if(all[j]==1){ res[j]=now; now++; int z=2; while((int)st.size()>0){ auto x=st.back(); if(all[x]==z){ z++; res[x]=now; st.pop_back(); now++; continue; } break; } } if(all[j]!=1&&all[j]!=-1){ st.push_back(j); } } if((int)st.size()>0){ cout<<-1<<"\n"; return 0; } for(int i=0;i<n;i++){ cout<<res[i]<<" "; } cout<<"\n"; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:27:6: warning: unused variable 'last' [-Wunused-variable]
   27 |  int last=-1;
      |      ^~~~
#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...