Submission #593042

#TimeUsernameProblemLanguageResultExecution timeMemory
593042pooyashamsWatermelon (INOI20_watermelon)C++14
0 / 100
13 ms2772 KiB
#include <algorithm> #include <iostream> #include <numeric> #include <cstring> #include <iomanip> #include <vector> #include <bitset> #include <stack> #include <queue> #include <cmath> #include <set> #include <map> #define endl '\n' #define X first #define Y second using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; const int maxn = 1e5+20; int brr[maxn]; int smx[maxn]; int ans[maxn]; int bef[maxn]; int aft[maxn]; inline void die() { cout << -1 << endl; exit(0); } inline void join(int x) { int b = bef[x]; int a = aft[x]; bef[a] = b; aft[b] = a; } int32_t main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; // k == 1 set<int> rems; for(int i = 1; i <= n; i++) cin >> brr[i]; aft[0] = 1; for(int i = 1; i <= n+1; i++) { bef[i] = i-1; aft[i] = i+1; } bef[n+2] = n+1; // smx[n+1] = 0; for(int i = n; i > 0; i--) { if(brr[i] == -1) brr[i] = smx[i+1]+1; smx[i] = max(smx[i+1], brr[i]); if(brr[i] == 1) rems.insert(i); } //for(int i = 1; i <= n; i++) cerr << brr[i] << " "; //cerr << endl; for(int i = 1; i <= n; i++) { if(rems.empty()) die(); int x = *rems.begin(); rems.erase(rems.begin()); ans[x] = i; if(brr[bef[x]] == brr[x]+1) rems.insert(bef[x]); join(x); } for(int i = 1; i <= n; i++) cout << ans[i] << " "; cout << endl; return 0; }
#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...