/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 764.0 KiB
#2 Accepted 1ms 540.0 KiB
#3 Accepted 1ms 540.0 KiB
#4 Accepted 24ms 2.309 MiB
#5 Accepted 27ms 3.047 MiB
#6 Accepted 24ms 2.309 MiB
#7 Accepted 24ms 2.316 MiB
#8 Accepted 30ms 3.125 MiB
#9 Accepted 37ms 3.312 MiB
#10 Accepted 27ms 3.055 MiB
#11 Accepted 27ms 3.062 MiB
#12 Accepted 28ms 3.203 MiB
#13 Accepted 29ms 3.059 MiB
#14 Accepted 31ms 3.062 MiB
#15 Accepted 28ms 3.059 MiB
#16 Accepted 28ms 3.059 MiB
#17 Accepted 28ms 3.059 MiB
#18 Accepted 28ms 3.051 MiB
#19 Accepted 34ms 3.059 MiB
#20 Accepted 31ms 3.062 MiB

Code

/*
 *   Copyright (c) 2024 Emon Thakur
 *   All rights reserved.
 */
#include<bits/stdc++.h>
using namespace std;

//ofstream file("output19.txt");

void solve()
{
    int n; cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    int b[n]={0};

    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(b[i]==0)
        {
            ++ans;
            int j=i;
            while(j<n)
            {
                b[j]++;
                if(b[j]>1) break;
                j += a[j];
            }
        }
    }
    
    //file<<ans<<endl;
    for(int i=0;i<n;i++)
    {
        if(i+a[i]<n && b[i+a[i]]==1) cout<<ans+1<<" ";
        else cout<<ans<<" ";
    }
    cout<<endl;
    //for(int i=0;i<n;i++) cout<<b[i]<<" "; cout<<endl<<endl;
}
int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    //freopen("input19.txt","r",stdin);
    int t; cin>>t; while(t--) solve();
}

Information

Submit By
Type
Submission
Problem
P1066 Light switches
Language
C++20 (G++ 13.2.0)
Submit At
2024-06-10 21:20:02
Judged At
2024-06-10 21:20:02
Judged By
Score
100
Total Time
37ms
Peak Memory
3.312 MiB