답안 #81156

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
81156 2018-10-24T02:45:05 Z KemLove 고대 책들 (IOI17_books) C++14
0 / 100
45 ms 47388 KB
#include <bits/stdc++.h>
using namespace std;

typedef double db;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, int> pt;
typedef pair<int, ii> iii;
typedef vector<int> vi;

#define FOR(i, l, r) for(int i = l; i <= r; ++i)
#define FORD(i, l, r) for(int i = l; i >= r; --i)
#define REP(i, r) for(int i = 0; i < int(r); ++i)
#define REPD(i, r) for(int i = int(r)-1; i >= 0; --i)
#define fi first
#define se second
#define x first
#define y second
#define sz size
#define endl '\n'
#define debug(x) cout << #x << " = " << x << endl;
#define boost ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mk make_pair

const int Nmax = 2e6 + 10;
const ll inf = 1e9;
const db _eps = 1e-15;

vi a[Nmax];
int n, s, last, startlast;
ll sum;
bool avail[Nmax];

void visit(int u) {
    last = u;
    avail[u] = true;
    REP(i, a[u].sz()) {
        int v = a[u][i];
        sum += 1LL * abs(v - u);
        if (avail[v] == false) {
            visit(v);
        }
    }
}

ll minimum_walk(vi p, int s) {
    s++; n = p.sz();
    FOR(i, 1, n) {
        a[i].push_back(p[i-1]);
    }
    startlast = s;
    FOR(i, s, n) {
        if (avail[i]) continue;
        sum += abs(i - startlast);
        visit(i);
        startlast = i;
    }
    FORD(i, s - 1, 1) {
        if (avail[i]) continue;
        sum += abs(i - startlast);
        visit(i);
        startlast = i;
    }
    return 1LL * abs(s - startlast) + sum;
}

# 결과 실행 시간 메모리 Grader output
1 Incorrect 45 ms 47352 KB 3rd lines differ - on the 1st token, expected: '6', found: '10'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 45 ms 47352 KB 3rd lines differ - on the 1st token, expected: '6', found: '10'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 45 ms 47352 KB 3rd lines differ - on the 1st token, expected: '6', found: '10'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 45 ms 47388 KB 3rd lines differ - on the 1st token, expected: '3304', found: '5288'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 45 ms 47352 KB 3rd lines differ - on the 1st token, expected: '6', found: '10'
2 Halted 0 ms 0 KB -