답안 #1028958

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1028958 2024-07-20T10:45:49 Z DorostWef 고대 책들 (IOI17_books) C++17
22 / 100
810 ms 23120 KB
#include "books.h"
#include <bits/stdc++.h>

#pragma GCC optimze ("O3, unroll-loops")
#pragma GCC target ("avx2")

using namespace std;
typedef long long ll;

const int N = 1023;
bool vis[N];
vector <int> c[N];
int l[N], r[N];
int n;
int dis[N][N];

long long minimum_walk(std::vector<int> p, int s) {
	long long ans = 0;
	n = (int)p.size();
	for (int i = 0; i < n; i++) {
		ans += abs (p[i] - i);
	}
	int w = s;
	for (int i = 0; i < n; i++) {
		if (!vis[i]) {
			l[i] = i;
			r[i] = i;
			c[i] = {i};
			int j = i;
			while (p[j] != i) {
				j = p[j];
				if (j == s)
					w = i;
				l[i] = min(l[i], j);
				r[i] = max(r[i], j);
				c[i].push_back(j);
				vis[j] = true;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i != j)
				dis[i][j] = N;
			else
				dis[i][j] = 0;
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			for (int x : c[j]) {
				if (x >= l[i] && x <= r[i]) {
					dis[i][j] = 0;
				}
				dis[i][j] = min(dis[i][j], abs(l[i] - x));
				dis[i][j] = min(dis[i][j], abs(r[i] - x));
			}
		}
	}
	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				dis[i][j] = min (dis[i][j], dis[i][k] + dis[k][j]);
			}
		}
	}
	int mx = 0;
	for (int j = 0; j < n; j++) {
		if (dis[w][j] != N && c[j].size() >= 2) {
			mx = max (mx, dis[w][j]);
		}
	}
	return ans + 2 * mx;
}

Compilation message

books.cpp:4: warning: ignoring '#pragma GCC optimze' [-Wunknown-pragmas]
    4 | #pragma GCC optimze ("O3, unroll-loops")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 464 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 464 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 665 ms 4444 KB Output is correct
20 Correct 667 ms 4468 KB Output is correct
21 Correct 707 ms 4444 KB Output is correct
22 Correct 711 ms 4692 KB Output is correct
23 Correct 744 ms 4480 KB Output is correct
24 Correct 810 ms 4444 KB Output is correct
25 Correct 698 ms 4484 KB Output is correct
26 Correct 751 ms 4444 KB Output is correct
27 Correct 666 ms 4444 KB Output is correct
28 Correct 640 ms 4444 KB Output is correct
29 Correct 668 ms 4440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 464 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 665 ms 4444 KB Output is correct
20 Correct 667 ms 4468 KB Output is correct
21 Correct 707 ms 4444 KB Output is correct
22 Correct 711 ms 4692 KB Output is correct
23 Correct 744 ms 4480 KB Output is correct
24 Correct 810 ms 4444 KB Output is correct
25 Correct 698 ms 4484 KB Output is correct
26 Correct 751 ms 4444 KB Output is correct
27 Correct 666 ms 4444 KB Output is correct
28 Correct 640 ms 4444 KB Output is correct
29 Correct 668 ms 4440 KB Output is correct
30 Runtime error 86 ms 23120 KB Execution killed with signal 11
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 644 ms 4692 KB Output is correct
2 Correct 756 ms 4444 KB Output is correct
3 Correct 653 ms 4440 KB Output is correct
4 Incorrect 681 ms 4444 KB 3rd lines differ - on the 1st token, expected: '2094', found: '1592'
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 464 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 665 ms 4444 KB Output is correct
20 Correct 667 ms 4468 KB Output is correct
21 Correct 707 ms 4444 KB Output is correct
22 Correct 711 ms 4692 KB Output is correct
23 Correct 744 ms 4480 KB Output is correct
24 Correct 810 ms 4444 KB Output is correct
25 Correct 698 ms 4484 KB Output is correct
26 Correct 751 ms 4444 KB Output is correct
27 Correct 666 ms 4444 KB Output is correct
28 Correct 640 ms 4444 KB Output is correct
29 Correct 668 ms 4440 KB Output is correct
30 Runtime error 86 ms 23120 KB Execution killed with signal 11
31 Halted 0 ms 0 KB -