105892024-04-06 10:10:51UVinceMágikus sorozatcpp17Wrong answer 15/10068ms23712 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;
    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]});
        }
        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 (last.top().second==n){
                    if (a[i-p]==1) a[i]==2;
                    else a[i]=5-a[i-p];
                }
            }
        }
    }
    for (ll i : a) cout<<i<<" ";
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms2100 KiB
2Accepted4ms2684 KiB
subtask215/15
3Accepted3ms2628 KiB
4Accepted3ms2768 KiB
5Accepted3ms2972 KiB
subtask30/15
6Accepted3ms3000 KiB
7Accepted3ms3100 KiB
8Accepted3ms3124 KiB
9Accepted3ms3116 KiB
10Wrong answer2ms3116 KiB
subtask40/30
11Wrong answer3ms3428 KiB
12Accepted3ms3464 KiB
13Wrong answer3ms3764 KiB
14Wrong answer3ms3960 KiB
subtask50/40
15Accepted52ms13144 KiB
16Wrong answer52ms13104 KiB
17Wrong answer52ms13096 KiB
18Wrong answer54ms13308 KiB
19Wrong answer57ms13420 KiB
20Wrong answer59ms13468 KiB
21Wrong answer59ms13764 KiB
22Wrong answer59ms13508 KiB
23Wrong answer59ms13540 KiB
24Wrong answer54ms13668 KiB
25Wrong answer54ms13668 KiB
26Wrong answer57ms13744 KiB
27Wrong answer46ms12540 KiB
28Wrong answer54ms14860 KiB
29Wrong answer54ms14240 KiB
30Accepted68ms23712 KiB
31Accepted61ms18588 KiB
32Accepted56ms15844 KiB