답안 #302013

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
302013 2020-09-18T11:14:29 Z kevlee 고대 책들 (IOI17_books) C++17
0 / 100
1 ms 384 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mod 1000000007
#define h1 7897897897897897
#define h2 7897466719774591
#define b1 98762051
#define b2 98765431
#define inf 1000000000
#define pi 3.1415926535897932384626
#define LMAX 9223372036854775807
#define ll long long
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pii>
#define SET(a, b) memset(a, b, sizeof(a))
#define all(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
bool first_cycle;
int p[1000005], n;
bool vis[1000005];
ll ans;
void dfs(int x) {
  if (vis[x]) return;
  vis[x] = true;
  ans += abs(x - p[x]);
  dfs(p[x]);
}
long long minimum_walk(vector<int> perm, int s) {
  n = perm.size();
  FOR(i, 0, n-1) p[i] = perm[i];
  int cycle = 0;
  vi v;
  FOR(i, 0, n-1) {
    if (!vis[i]) {
      cycle++;
      if (p[i] == i) {
        vis[i] = true;
        continue;
      }
      dfs(i);
      v.pb(i);
    }
  }
  if (cycle == 1) {
    return ans;
  }
  int v1 = (v.size() > 1 ? v[1] : 0);
  ans += v.back() - v1;
  int cur = p[0];
  int add = v.back();
  while (cur != 0) {
    if (cur < v1) add = min(add, abs(v1 - cur) + abs(v.back() - p[cur]) - abs(cur - p[cur]));
    cur = p[cur];
  }
  ans += add;
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Incorrect 1 ms 384 KB 3rd lines differ - on the 1st token, expected: '8', found: '9'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Incorrect 1 ms 384 KB 3rd lines differ - on the 1st token, expected: '8', found: '9'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Incorrect 1 ms 384 KB 3rd lines differ - on the 1st token, expected: '8', found: '9'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Incorrect 1 ms 384 KB 3rd lines differ - on the 1st token, expected: '8', found: '9'
7 Halted 0 ms 0 KB -