# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
782159 | amirhoseinfar1385 | Watermelon (INOI20_watermelon) | C++17 | 6 ms | 1368 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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);
}
}
for(int i=0;i<n;i++){
cout<<res[i]<<" ";
}
cout<<"\n";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |