提出 #73303930
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
void O_O() {
int n;
cin >> n;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
vector<int> ans(n + 1);
auto dfs = [&](auto& dfs, int i) -> int {
if (i == a[i]) return ans[i] = a[i];
if (ans[i]) return ans[i];
return ans[i] = dfs(dfs, a[i]);
};
for (int i = 1; i <= n; i++) {
dfs(dfs, i);
}
for (int i = 1; i <= n; i++) {
cout << ans[i] << ' ';
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int TC = 1;
//cin >> TC;
while (TC--) {
O_O();
if (TC) cout << '\n';
}
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | C - Sugoroku Destination |
| ユーザ | Mariouma |
| 言語 | C++23 (GCC 15.2.0) |
| 得点 | 300 |
| コード長 | 748 Byte |
| 結果 | AC |
| 実行時間 | 43 ms |
| メモリ | 15648 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 300 / 300 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| 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 | 1 ms | 3612 KiB |
| 00_sample_01.txt | AC | 1 ms | 3588 KiB |
| 00_sample_02.txt | AC | 1 ms | 3464 KiB |
| 01_random_03.txt | AC | 42 ms | 7952 KiB |
| 01_random_04.txt | AC | 43 ms | 7952 KiB |
| 01_random_05.txt | AC | 41 ms | 7960 KiB |
| 01_random_06.txt | AC | 41 ms | 7956 KiB |
| 01_random_07.txt | AC | 41 ms | 7964 KiB |
| 01_random_08.txt | AC | 42 ms | 7964 KiB |
| 01_random_09.txt | AC | 42 ms | 7952 KiB |
| 01_random_10.txt | AC | 42 ms | 7964 KiB |
| 01_random_11.txt | AC | 17 ms | 4872 KiB |
| 01_random_12.txt | AC | 14 ms | 4524 KiB |
| 01_random_13.txt | AC | 37 ms | 7244 KiB |
| 01_random_14.txt | AC | 4 ms | 3704 KiB |
| 01_random_15.txt | AC | 41 ms | 7948 KiB |
| 01_random_16.txt | AC | 2 ms | 3448 KiB |
| 01_random_17.txt | AC | 41 ms | 15648 KiB |