답안 #892954

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
892954 2023-12-26T08:49:04 Z abcvuitunggio 고대 책들 (IOI17_books) C++17
50 / 100
164 ms 30584 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
int vis[1000001],r[1000001],g[1000001],nxt[1000001];
vector <pair <int, pair <int, int>>> e;
long long minimum_walk(vector <int> p, int s){
    int n=p.size(),lo=n,hi=0;
    iota(nxt,nxt+n,0);
    vector <pair <int, int>> tmp;
    long long d=0;
    for (int i=0;i<n;i++)
        if (!vis[i]){
            int x=i;
            while (!vis[x]){
                vis[x]=1;
                g[x]=i;
                r[i]=max(r[i],x);
                d+=abs(x-p[x]);
                x=p[x];
            }
          	if (r[i]!=i||i==s){
                lo=min(lo,i);
                hi=max(hi,r[i]);
          	}
        }
    int L=g[s],R=r[g[s]];
    while (L>lo||R<hi){
        if (nxt[L]!=R){
            int j=nxt[L]+1;
            nxt[L]=j;
            L=min(L,g[j]);
            R=max(R,r[g[j]]);
            continue;
        }
        d+=2;
        if (L>lo&&r[g[L-1]]>=R+1||R==hi){
            R=r[g[L-1]];
            L=g[L-1];
            continue;
        }
        L=min(L,g[R+1]);
        R=r[g[R+1]];
    }
    return d;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:36:17: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   36 |         if (L>lo&&r[g[L-1]]>=R+1||R==hi){
      |             ~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2504 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2504 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2496 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2504 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2496 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 116 ms 26732 KB Output is correct
31 Correct 114 ms 26704 KB Output is correct
32 Correct 102 ms 30568 KB Output is correct
33 Correct 112 ms 30548 KB Output is correct
34 Correct 111 ms 30544 KB Output is correct
35 Correct 135 ms 30544 KB Output is correct
36 Correct 117 ms 30584 KB Output is correct
37 Correct 105 ms 30584 KB Output is correct
38 Correct 107 ms 30032 KB Output is correct
39 Correct 107 ms 29828 KB Output is correct
40 Correct 107 ms 27728 KB Output is correct
41 Correct 164 ms 26608 KB Output is correct
42 Correct 113 ms 26876 KB Output is correct
43 Correct 103 ms 30544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3506'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2504 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2496 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 116 ms 26732 KB Output is correct
31 Correct 114 ms 26704 KB Output is correct
32 Correct 102 ms 30568 KB Output is correct
33 Correct 112 ms 30548 KB Output is correct
34 Correct 111 ms 30544 KB Output is correct
35 Correct 135 ms 30544 KB Output is correct
36 Correct 117 ms 30584 KB Output is correct
37 Correct 105 ms 30584 KB Output is correct
38 Correct 107 ms 30032 KB Output is correct
39 Correct 107 ms 29828 KB Output is correct
40 Correct 107 ms 27728 KB Output is correct
41 Correct 164 ms 26608 KB Output is correct
42 Correct 113 ms 26876 KB Output is correct
43 Correct 103 ms 30544 KB Output is correct
44 Incorrect 1 ms 2396 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3506'
45 Halted 0 ms 0 KB -