답안 #421493

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
421493 2021-06-09T08:18:28 Z MarcoMeijer 고대 책들 (IOI17_books) C++14
50 / 100
211 ms 16116 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;

// macros
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define INF 1e9
#define EPS 1e-9
#define pb push_back
#define popb pop_back
#define fi first
#define se second
#define sz size()
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll minimum_walk(vi p, int s) {
    int n = p.size();
    ll ans = 0;
    vi visited; visited.assign(n,0);

    /*if(s == 0) {
        ll rightMost = 0;

        RE(i,n) {
            if(visited[i]) continue;
            if(i == p[i]) continue;
            int u = p[i];
            ans += (ll)abs(i-p[i]);
            if(rightMost < i) ans += (i-rightMost)*2ll;
            while(u != i) {
                visited[u] = 1;
                rightMost = max<ll>(rightMost, u);
                ans += (ll)abs(u - p[u]);
                u = p[u];
            }
        }
    } else {*/
        int ls=s, rs=s;
        queue<int> q; q.push(s);

        while(ls != 0 || rs != n-1 || !q.empty()) {
            while(!q.empty()) {
                int i = q.front(); q.pop();
                if(visited[i]) continue;
                if(i == p[i]) continue;
                int u = p[i];
                ans += (ll)abs(i-p[i]);
                while(u != i) {
                    visited[u] = 1;
                    ans += (ll)abs(u - p[u]);

                    while(ls > u) q.push(--ls);
                    while(rs < u) q.push(++rs);

                    u = p[u];
                }
            }

            int leftSize = INF, rightSize = INF;
            REV(i,0   ,ls) if(p[i] != i) {
                leftSize  = ls - i;
                break;
            }
            REP(i,rs+1,n ) if(p[i] != i) {
                rightSize = i  - rs;
                break;
            }

            if(leftSize == INF && rightSize == INF) {
                break;
            }
            if(leftSize < rightSize) {
                RE(_,leftSize) q.push(--ls), ans += 2ll;
            } else {
                RE(_,rightSize) q.push(++rs), ans += 2ll;
            }
        }
    // }

	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 202 ms 16068 KB Output is correct
31 Correct 211 ms 16112 KB Output is correct
32 Correct 128 ms 12008 KB Output is correct
33 Correct 131 ms 12032 KB Output is correct
34 Correct 132 ms 12004 KB Output is correct
35 Correct 134 ms 12016 KB Output is correct
36 Correct 144 ms 12012 KB Output is correct
37 Correct 132 ms 12004 KB Output is correct
38 Correct 136 ms 11972 KB Output is correct
39 Correct 133 ms 12020 KB Output is correct
40 Correct 135 ms 12144 KB Output is correct
41 Correct 192 ms 14052 KB Output is correct
42 Correct 147 ms 13540 KB Output is correct
43 Correct 134 ms 16116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3324'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 202 ms 16068 KB Output is correct
31 Correct 211 ms 16112 KB Output is correct
32 Correct 128 ms 12008 KB Output is correct
33 Correct 131 ms 12032 KB Output is correct
34 Correct 132 ms 12004 KB Output is correct
35 Correct 134 ms 12016 KB Output is correct
36 Correct 144 ms 12012 KB Output is correct
37 Correct 132 ms 12004 KB Output is correct
38 Correct 136 ms 11972 KB Output is correct
39 Correct 133 ms 12020 KB Output is correct
40 Correct 135 ms 12144 KB Output is correct
41 Correct 192 ms 14052 KB Output is correct
42 Correct 147 ms 13540 KB Output is correct
43 Correct 134 ms 16116 KB Output is correct
44 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3324'
45 Halted 0 ms 0 KB -