/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 332.0 KiB
#2 Accepted 3ms 332.0 KiB
#3 Accepted 3ms 544.0 KiB
#4 Accepted 47ms 2.34 MiB
#5 Accepted 54ms 3.082 MiB
#6 Accepted 50ms 2.367 MiB
#7 Accepted 49ms 2.332 MiB
#8 Accepted 58ms 3.016 MiB
#9 Accepted 81ms 3.406 MiB
#10 Accepted 60ms 3.172 MiB
#11 Accepted 58ms 3.008 MiB
#12 Accepted 58ms 3.043 MiB
#13 Accepted 53ms 3.043 MiB
#14 Accepted 66ms 3.055 MiB
#15 Accepted 64ms 3.023 MiB
#16 Accepted 64ms 2.984 MiB
#17 Accepted 55ms 3.188 MiB
#18 Accepted 55ms 3.254 MiB
#19 Accepted 56ms 3.215 MiB
#20 Accepted 59ms 2.996 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-11-11 03:28:58
Judged By
Score
100
Total Time
81ms
Peak Memory
3.406 MiB