Submission #5391899


Source Code Expand

#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl

using namespace std;

template<typename S,typename T>auto&operator<<(ostream&o,pair<S,T>p){return o<<"{"<<p.fi<<","<<p.se<<"}";}
template<typename T>auto&operator<<(ostream&o,set<T>s){for(auto&e:s)o<<e<<" ";return o;}
template<typename S,typename T,typename U>
auto&operator<<(ostream&o,priority_queue<S,T,U>q){while(!q.empty())o<<q.top()<<" ",q.pop();return o;}
template<typename K,typename T>auto&operator<<(ostream&o,map<K,T>m){for(auto&e:m)o<<e<<" ";return o;}
template<typename T>auto&operator<<(ostream&o,vector<T>v){for(auto&e:v)o<<e<<" ";return o;}
void ashow(){cout<<endl;}template<typename T,typename...A>void ashow(T t,A...a){cout<<t<<" ";ashow(a...);}

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef vector<string> vs;

const int MAX_N = 100005;

vector<int> num[MAX_N];

void MP(const vi& S, vector<int>& res){
    int n = (int)S.size(), j = 0;
    res.resize(n, 0);
    vi next(n, 0);
    for(int i = 0; i < n-1; i++){
        while(S[i+1] != S[j] && --j >= 0) j = next[j];
        res[i+1] = ++j;
        if(S[i+2] == S[j]) next[i+1] = (j > 0) ? next[j-1] : 0;
        else next[i+1] = j;
    }
}

#define getchar getchar_unlocked

inline int in() {
    int n = 0; short c;
    while ((c = getchar()) >= '0') n = n * 10 + c - '0';
    return n;
}

int main()
{
    int n = in(), j = 0;
    vi res(n, 0);
    rep(i,n) res[i] = in();
    vi a(n, 1);
    int id = 1;
    for(int i = 0; i < n-1; i++){
        for(; j >= -1;){
            if(j+1 < res[i+1]){
                cout << "No\n";
                return false;
            }else if(j+1 == res[i+1]){
                a[i+1] = (++j <= 0) ? ++id : a[j-1];
                break;
            }else if(--j >= 0){
                j = res[j];
            }
        }
    }
    vi check;
    MP(a, check);
    if(res == check){
        cout << "Yes\n";
        rep(i,n){
            cout << a[i] << " ";
        }
        cout << "\n";
    }else{
        cout << "No\n";
    }
    return 0;
}

Submission Info

Submission Time
Task H - 根室の巫女
User kopricky
Language C++14 (GCC 5.4.1)
Score 700
Code Size 2867 Byte
Status AC
Exec Time 13 ms
Memory 4220 KiB

Judge Result

Set Name Sample Subtask1
Score / Max Score 0 / 0 700 / 700
Status
AC × 2
AC × 32
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
Subtask1 sample_01.txt, sample_02.txt, sub1_01.txt, sub1_02.txt, sub1_03.txt, sub1_04.txt, sub1_05.txt, sub1_06.txt, sub1_07.txt, sub1_08.txt, sub1_09.txt, sub1_10.txt, sub1_11.txt, sub1_12.txt, sub1_13.txt, sub1_14.txt, sub1_15.txt, sub1_16.txt, sub1_17.txt, sub1_18.txt, sub1_19.txt, sub1_20.txt, sub1_21.txt, sub1_22.txt, sub1_23.txt, sub1_24.txt, sub1_25.txt, sub1_26.txt, sub1_27.txt, sub1_28.txt, sub1_29.txt, sub1_30.txt
Case Name Status Exec Time Memory
sample_01.txt AC 2 ms 2560 KiB
sample_02.txt AC 2 ms 2560 KiB
sub1_01.txt AC 3 ms 2688 KiB
sub1_02.txt AC 6 ms 3200 KiB
sub1_03.txt AC 13 ms 4220 KiB
sub1_04.txt AC 12 ms 4012 KiB
sub1_05.txt AC 4 ms 2944 KiB
sub1_06.txt AC 2 ms 2560 KiB
sub1_07.txt AC 12 ms 4116 KiB
sub1_08.txt AC 3 ms 2944 KiB
sub1_09.txt AC 10 ms 3712 KiB
sub1_10.txt AC 9 ms 3484 KiB
sub1_11.txt AC 12 ms 3968 KiB
sub1_12.txt AC 13 ms 4096 KiB
sub1_13.txt AC 13 ms 4096 KiB
sub1_14.txt AC 2 ms 2560 KiB
sub1_15.txt AC 12 ms 4124 KiB
sub1_16.txt AC 12 ms 4000 KiB
sub1_17.txt AC 2 ms 2560 KiB
sub1_18.txt AC 10 ms 3712 KiB
sub1_19.txt AC 13 ms 4104 KiB
sub1_20.txt AC 3 ms 2944 KiB
sub1_21.txt AC 11 ms 3840 KiB
sub1_22.txt AC 10 ms 3712 KiB
sub1_23.txt AC 2 ms 2560 KiB
sub1_24.txt AC 11 ms 4096 KiB
sub1_25.txt AC 3 ms 2560 KiB
sub1_26.txt AC 2 ms 2560 KiB
sub1_27.txt AC 6 ms 3200 KiB
sub1_28.txt AC 8 ms 3608 KiB
sub1_29.txt AC 4 ms 2944 KiB
sub1_30.txt AC 2 ms 2560 KiB