답안 #413257

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
413257 2021-05-28T11:59:23 Z 반딧불(#7606) Through Another Maze Darkly (CCO21_day1problem3) C++17
0 / 25
4924 ms 1048580 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int LIM = 2000000;

int n, q;
int deg[800002];
vector<int> link[800002];
int pnt[800002], stat[800002];
vector<int> vec;

int LOW[LIM+1];
int isStart;

int nextVertex(int now){
    if(pnt[now] == stat[now]) isStart--;
    pnt[now] = (pnt[now] + 1) % deg[now];
    if(pnt[now] == stat[now]) isStart++;
    now = link[now][pnt[now]];
    return now;
}

int main(){
    scanf("%d %d", &n, &q);
    for(int i=1; i<=n; i++){
        scanf("%d", &deg[i]);
        for(int j=0; j<deg[i]; j++){
            int x;
            scanf("%d", &x);
            link[i].push_back(x);
        }
    }

    isStart = n;
    int now = 1, startVert;
    for(int turn=0; turn<LIM; turn++){
        LOW[turn] = now;
        now = nextVertex(now);
    }
    for(int i=1; i<=n; i++) stat[i] = pnt[i];
    isStart = n, startVert = now;
    while(1){
        if(startVert == now && isStart == n && !vec.empty()) break;
        vec.push_back(now);
        now = nextVertex(now);
    }

    while(q--){
        ll x;
        scanf("%lld", &x);
        if(x < LIM) printf("%d\n", LOW[x]);
        else printf("%d\n", vec[(x - LIM) % (int)vec.size()]);
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     scanf("%d %d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         scanf("%d", &deg[i]);
      |         ~~~~~^~~~~~~~~~~~~~~
Main.cpp:31:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |             scanf("%d", &x);
      |             ~~~~~^~~~~~~~~~
Main.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         scanf("%lld", &x);
      |         ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 26904 KB Output is correct
2 Runtime error 3231 ms 1048580 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 26828 KB Output is correct
2 Correct 42 ms 26932 KB Output is correct
3 Correct 53 ms 26884 KB Output is correct
4 Correct 52 ms 26996 KB Output is correct
5 Correct 63 ms 27076 KB Output is correct
6 Correct 60 ms 26952 KB Output is correct
7 Correct 58 ms 27052 KB Output is correct
8 Correct 57 ms 27040 KB Output is correct
9 Correct 56 ms 26984 KB Output is correct
10 Correct 63 ms 26992 KB Output is correct
11 Correct 73 ms 26952 KB Output is correct
12 Runtime error 2483 ms 1048580 KB Execution killed with signal 9
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4924 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 26904 KB Output is correct
2 Runtime error 3231 ms 1048580 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -