답안 #1028952

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1028952 2024-07-20T10:43:22 Z DorostWef 고대 책들 (IOI17_books) C++17
0 / 100
663 ms 4440 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] = min(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 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 663 ms 4440 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3878'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -