Submission #73303673


Source Code Expand

#include <bits/stdc++.h>
#define rep(i, s, e) for (ll i = (ll)(s); i < (ll)(e); ++i)
#define rrep(i, s ,e) for (ll i = (ll)(s); i > (ll)(e); --i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 998244353;
//const ll MOD = 1000000007;

int main(){
    cin.tie(0);cout.tie(0);
    ios_base::sync_with_stdio(false);

    ll n;cin >> n;
    vector<ll> a(n);
    rep(i,0,n){
        cin >> a[i];
        a[i]--;
    }
   vector<ll> ans(n,-1);
   vector<ll> seen(n,-1);
   rep(i,0,n){
    if(ans[i] != -1)continue;
    ll now = i;
    vector<ll> v;
    while(1){
        seen[now] = 1;
        v.emplace_back(now);
        now = a[now];
        if(now == a[now])break;
    }
    for(auto x:v)ans[x] = now+1;
   }
   rep(i,0,n)cout << ans[i] << " ";
   cout << endl;
}
   

Submission Info

Submission Time
Task C - Sugoroku Destination
User KH8047
Language C++23 (GCC 15.2.0)
Score 300
Code Size 841 Byte
Status AC
Exec Time 95 ms
Memory 19260 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 18
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3620 KiB
00_sample_01.txt AC 1 ms 3464 KiB
00_sample_02.txt AC 1 ms 3556 KiB
01_random_03.txt AC 92 ms 15800 KiB
01_random_04.txt AC 95 ms 15796 KiB
01_random_05.txt AC 90 ms 15804 KiB
01_random_06.txt AC 91 ms 15796 KiB
01_random_07.txt AC 92 ms 15808 KiB
01_random_08.txt AC 92 ms 15812 KiB
01_random_09.txt AC 91 ms 15800 KiB
01_random_10.txt AC 91 ms 15796 KiB
01_random_11.txt AC 30 ms 7672 KiB
01_random_12.txt AC 26 ms 6904 KiB
01_random_13.txt AC 79 ms 14108 KiB
01_random_14.txt AC 6 ms 4036 KiB
01_random_15.txt AC 92 ms 15780 KiB
01_random_16.txt AC 2 ms 3476 KiB
01_random_17.txt AC 49 ms 19260 KiB