105882024-04-06 10:09:14UVinceMágikus sorozatcpp17Wrong answer 15/10068ms13320 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<int> z(n),a(n);
    stack<pair<int,int>> last;
    for (int 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 (int i : a) cout<<i<<" ";
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms2100 KiB
2Accepted4ms2436 KiB
subtask215/15
3Accepted3ms2308 KiB
4Accepted3ms2480 KiB
5Accepted3ms2800 KiB
subtask30/15
6Accepted3ms2724 KiB
7Accepted3ms2852 KiB
8Accepted3ms3064 KiB
9Accepted2ms3064 KiB
10Wrong answer3ms3068 KiB
subtask40/30
11Wrong answer3ms3100 KiB
12Accepted3ms3096 KiB
13Wrong answer3ms3096 KiB
14Wrong answer3ms3348 KiB
subtask50/40
15Accepted52ms7828 KiB
16Wrong answer52ms7820 KiB
17Wrong answer54ms7828 KiB
18Wrong answer54ms8036 KiB
19Wrong answer59ms8064 KiB
20Wrong answer59ms8088 KiB
21Wrong answer61ms8096 KiB
22Wrong answer59ms8064 KiB
23Wrong answer61ms8396 KiB
24Wrong answer54ms8256 KiB
25Wrong answer54ms8260 KiB
26Wrong answer57ms8260 KiB
27Wrong answer46ms7708 KiB
28Wrong answer54ms9104 KiB
29Wrong answer52ms8964 KiB
30Accepted68ms13320 KiB
31Accepted61ms11028 KiB
32Accepted57ms9676 KiB