10590 | 2024-04-06 10:37:50 | UVince | Mágikus sorozat | cpp17 | Accepted 100/100 | 82ms | 41216 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define all(a) a.begin(),a.end()
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
//freopen("be2.txt","r",stdin);
int n;
cin >> n;
vector<ll> z(n),a(n);
stack<pair<ll,ll>> last;
vector<vector<pair<ll,ll>>> mark(n);
for (ll i = 0; i < n; i++)
{
cin>>z[i];
if (z[i]!=0) {
a[i]=1;
while (!last.empty() && last.top().first+last.top().second-1<=i) last.pop();
last.push({i,z[i]});
if (i+z[i]<n) mark[i+z[i]].push_back({i,z[i]});
}
else {
a[i]=2;
auto [f,l]=last.top();
if (f+l-1>=i){
a[i]=a[i-f];
}
else {
auto [p,q]=last.top();
last.pop();
if (!mark[i].empty()){
vector<bool> allowed(1e4,true);
for (auto [x,y] : mark[i]){
allowed[a[y]]=false;
}
for (int z=2;z<1e4;z++){
if (allowed[z]){
a[i]=z;
break;
}
}
}
}
}
}
for (ll i : a) cout<<i<<" ";
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1696 KiB | ||||
2 | Accepted | 4ms | 2712 KiB | ||||
subtask2 | 15/15 | ||||||
3 | Accepted | 3ms | 2508 KiB | ||||
4 | Accepted | 3ms | 2760 KiB | ||||
5 | Accepted | 3ms | 2692 KiB | ||||
subtask3 | 15/15 | ||||||
6 | Accepted | 3ms | 2600 KiB | ||||
7 | Accepted | 2ms | 2540 KiB | ||||
8 | Accepted | 3ms | 2760 KiB | ||||
9 | Accepted | 2ms | 2812 KiB | ||||
10 | Accepted | 3ms | 2936 KiB | ||||
subtask4 | 30/30 | ||||||
11 | Accepted | 3ms | 3284 KiB | ||||
12 | Accepted | 3ms | 3288 KiB | ||||
13 | Accepted | 3ms | 3348 KiB | ||||
14 | Accepted | 3ms | 3264 KiB | ||||
subtask5 | 40/40 | ||||||
15 | Accepted | 59ms | 27080 KiB | ||||
16 | Accepted | 70ms | 30064 KiB | ||||
17 | Accepted | 79ms | 40152 KiB | ||||
18 | Accepted | 79ms | 41216 KiB | ||||
19 | Accepted | 82ms | 40572 KiB | ||||
20 | Accepted | 75ms | 40348 KiB | ||||
21 | Accepted | 72ms | 38116 KiB | ||||
22 | Accepted | 71ms | 38684 KiB | ||||
23 | Accepted | 76ms | 38212 KiB | ||||
24 | Accepted | 75ms | 34156 KiB | ||||
25 | Accepted | 72ms | 39876 KiB | ||||
26 | Accepted | 75ms | 39824 KiB | ||||
27 | Accepted | 71ms | 31412 KiB | ||||
28 | Accepted | 68ms | 30716 KiB | ||||
29 | Accepted | 64ms | 29220 KiB | ||||
30 | Accepted | 72ms | 37508 KiB | ||||
31 | Accepted | 68ms | 32812 KiB | ||||
32 | Accepted | 63ms | 29748 KiB |