提出 #73306846


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
vector<int> a, dp;
int walk(int i){
    if(dp[i] != 0) return dp[i];
    if(a[i] == i) {
        dp[i] = i;
        return i;
    }
    int res = walk(a[i]);
    dp[i] = res;
    return res;
}
int main(){
    int n; cin >> n;
    dp.resize(n);
    for(int _ = 0; _ < n; _++){
        int ai; cin >> ai;
        a.push_back(ai-1);
    }
    for(int i = 0; i < n; i++){
        cout << walk(i)+1 << ' ';
    }
    cout << "\n";
}

提出情報

提出日時
問題 C - Sugoroku Destination
ユーザ mg00s
言語 C++ IOI-Style(GNU++20) (GCC 14.2.0)
得点 300
コード長 497 Byte
結果 AC
実行時間 105 ms
メモリ 15740 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 3
AC × 18
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 0 ms 1676 KiB
00_sample_01.txt AC 0 ms 1676 KiB
00_sample_02.txt AC 0 ms 1676 KiB
01_random_03.txt AC 103 ms 7800 KiB
01_random_04.txt AC 102 ms 7832 KiB
01_random_05.txt AC 105 ms 7820 KiB
01_random_06.txt AC 103 ms 7820 KiB
01_random_07.txt AC 103 ms 7768 KiB
01_random_08.txt AC 105 ms 7816 KiB
01_random_09.txt AC 104 ms 7716 KiB
01_random_10.txt AC 104 ms 7832 KiB
01_random_11.txt AC 36 ms 3480 KiB
01_random_12.txt AC 30 ms 3376 KiB
01_random_13.txt AC 90 ms 7088 KiB
01_random_14.txt AC 6 ms 2060 KiB
01_random_15.txt AC 103 ms 7708 KiB
01_random_16.txt AC 1 ms 1676 KiB
01_random_17.txt AC 94 ms 15740 KiB