105872024-04-06 09:37:07UVinceMágikus sorozatcpp17Wrong answer 0/10063ms29512 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);

    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;
            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 [f,l]=last.top();
                last.pop();
                if (last.top().second==n){
                    if (a[i-f]==1) a[i]==2;
                    else a[i]=5-a[i-f];
                }
            }
        }
    }
    for (int i : a) cout<<i<<" ";
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1824 KiB
2Wrong answer4ms2276 KiB
subtask20/15
3Accepted3ms2196 KiB
4Wrong answer3ms2308 KiB
5Wrong answer3ms2544 KiB
subtask30/15
6Accepted3ms2604 KiB
7Accepted3ms2836 KiB
8Accepted3ms3040 KiB
9Accepted3ms3396 KiB
10Wrong answer3ms3672 KiB
subtask40/30
11Wrong answer3ms3836 KiB
12Wrong answer3ms3980 KiB
13Wrong answer3ms4268 KiB
14Wrong answer3ms4492 KiB
subtask50/40
15Wrong answer48ms9380 KiB
16Wrong answer50ms10092 KiB
17Wrong answer52ms14536 KiB
18Wrong answer52ms16320 KiB
19Wrong answer54ms17600 KiB
20Wrong answer57ms18968 KiB
21Wrong answer57ms20336 KiB
22Wrong answer57ms21704 KiB
23Wrong answer57ms22900 KiB
24Wrong answer50ms20364 KiB
25Wrong answer52ms24236 KiB
26Wrong answer54ms25544 KiB
27Wrong answer43ms21804 KiB
28Wrong answer50ms22424 KiB
29Wrong answer50ms23148 KiB
30Accepted63ms29512 KiB
31Accepted56ms28488 KiB
32Accepted52ms27956 KiB