Submission #49443573


Source Code Expand

/**
 *  @the_hyp0cr1t3
 *  20.01.2024 17:34
**/
#include <bits/stdc++.h>

int main() {
    std::cin.tie(nullptr)->sync_with_stdio(false);

    int n, r;
    std::cin >> n;
    std::vector<int> nxt(n, -1);
    for (int i = 0; i < n; i++) {
        int x;
        std::cin >> x;
        if (x == -1) {
            r = i;
        } else {
            nxt[--x] = i;
        }
    }

    while (~r) {
        std::cout << r + 1 << ' ';
        r = nxt[r];
    }

}

Submission Info

Submission Time
Task C - Lining Up 2
User the_hyp0cr1t3
Language C++ 20 (gcc 12.2)
Score 300
Code Size 488 Byte
Status AC
Exec Time 31 ms
Memory 4396 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:24:31: warning: ‘r’ may be used uninitialized [-Wmaybe-uninitialized]
   24 |         std::cout << r + 1 << ' ';
      |                               ^~~
Main.cpp:10:12: note: ‘r’ was declared here
   10 |     int n, r;
      |            ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 32
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_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 01_handmade_06.txt, 01_handmade_07.txt, 01_handmade_08.txt, 01_handmade_09.txt, 01_handmade_10.txt, 01_handmade_11.txt, 01_handmade_12.txt, 01_handmade_13.txt, 01_handmade_14.txt, 01_handmade_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 02_random_20.txt, 02_random_21.txt, 02_random_22.txt, 02_random_23.txt, 02_random_24.txt, 02_random_25.txt, 02_random_26.txt, 02_random_27.txt, 02_random_28.txt, 02_random_29.txt, 02_random_30.txt, 02_random_31.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3476 KiB
00_sample_01.txt AC 1 ms 3508 KiB
00_sample_02.txt AC 1 ms 3400 KiB
01_handmade_03.txt AC 25 ms 4388 KiB
01_handmade_04.txt AC 25 ms 4300 KiB
01_handmade_05.txt AC 25 ms 4360 KiB
01_handmade_06.txt AC 25 ms 4284 KiB
01_handmade_07.txt AC 1 ms 3460 KiB
01_handmade_08.txt AC 1 ms 3516 KiB
01_handmade_09.txt AC 1 ms 3380 KiB
01_handmade_10.txt AC 1 ms 3472 KiB
01_handmade_11.txt AC 1 ms 3460 KiB
01_handmade_12.txt AC 1 ms 3516 KiB
01_handmade_13.txt AC 1 ms 3448 KiB
01_handmade_14.txt AC 1 ms 3516 KiB
01_handmade_15.txt AC 1 ms 3460 KiB
02_random_16.txt AC 30 ms 4340 KiB
02_random_17.txt AC 31 ms 4312 KiB
02_random_18.txt AC 30 ms 4296 KiB
02_random_19.txt AC 30 ms 4368 KiB
02_random_20.txt AC 31 ms 4340 KiB
02_random_21.txt AC 30 ms 4396 KiB
02_random_22.txt AC 30 ms 4308 KiB
02_random_23.txt AC 30 ms 4324 KiB
02_random_24.txt AC 11 ms 3596 KiB
02_random_25.txt AC 8 ms 3380 KiB
02_random_26.txt AC 4 ms 3504 KiB
02_random_27.txt AC 17 ms 3780 KiB
02_random_28.txt AC 15 ms 3512 KiB
02_random_29.txt AC 17 ms 3696 KiB
02_random_30.txt AC 30 ms 4076 KiB
02_random_31.txt AC 19 ms 3928 KiB