답안 #1028981

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1028981 2024-07-20T10:56:08 Z AmirAli_H1 고대 책들 (IOI17_books) C++17
50 / 100
118 ms 19984 KB
// In the name of Allah

#include <bits/stdc++.h>
#include "books.h"
using namespace std;

typedef		long long int			ll;
typedef		long double				ld;
typedef		pair<int, int>			pii;
typedef		pair<ll, ll>			pll;
typedef		complex<ld>				cld;

#define		all(x)					(x).begin(),(x).end()
#define		len(x)					((ll) (x).size())
#define		F						first
#define		S						second
#define		pb						push_back
#define		sep						' '
#define		endl					'\n'
#define		Mp						make_pair
#define		kill(x)					cout << x << '\n', exit(0)
#define		set_dec(x)				cout << fixed << setprecision(x);
#define		file_io(x,y)			freopen(x, "r", stdin); freopen(y, "w", stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 1e6 + 4;

int n; ll res;
int A[maxn], mark[maxn];
int sm[maxn], mn, mx;

void dfs(int v) {
	mark[v] = 1;
	mn = min(mn, v); mx = max(mx, v);
	if (!mark[A[v]]) dfs(A[v]);
}

ll minimum_walk(vector<int> p, int s) {
	n = len(p); res = 0;
	for (int i = 0; i < n; i++) {
		A[i] = p[i];
		res += abs(i - A[i]);
	}
	
	int m1 = s, m2 = s;
	for (int i = 0; i < n; i++) {
		if (A[i] != i) {
			m1 = min(m1, i); m2 = max(m2, i);
		}
		
		if (!mark[i]) {
			mn = i; mx = i;
			dfs(i);
			sm[mn]++; sm[mx]--;
		}
	}
	for (int i = 1; i < n; i++) {
		sm[i] += sm[i - 1];
	}
	
	for (int i = m1; i < m2; i++) {
		if (sm[i] == 0) res += 2;
	}
	return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 0 ms 2396 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 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2392 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2392 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 96 ms 19984 KB Output is correct
31 Correct 85 ms 19964 KB Output is correct
32 Correct 71 ms 19796 KB Output is correct
33 Correct 100 ms 19796 KB Output is correct
34 Correct 85 ms 19980 KB Output is correct
35 Correct 78 ms 19980 KB Output is correct
36 Correct 75 ms 19976 KB Output is correct
37 Correct 106 ms 19980 KB Output is correct
38 Correct 97 ms 19964 KB Output is correct
39 Correct 81 ms 19980 KB Output is correct
40 Correct 81 ms 19796 KB Output is correct
41 Correct 98 ms 19796 KB Output is correct
42 Correct 118 ms 19980 KB Output is correct
43 Correct 79 ms 19964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 2396 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2392 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 96 ms 19984 KB Output is correct
31 Correct 85 ms 19964 KB Output is correct
32 Correct 71 ms 19796 KB Output is correct
33 Correct 100 ms 19796 KB Output is correct
34 Correct 85 ms 19980 KB Output is correct
35 Correct 78 ms 19980 KB Output is correct
36 Correct 75 ms 19976 KB Output is correct
37 Correct 106 ms 19980 KB Output is correct
38 Correct 97 ms 19964 KB Output is correct
39 Correct 81 ms 19980 KB Output is correct
40 Correct 81 ms 19796 KB Output is correct
41 Correct 98 ms 19796 KB Output is correct
42 Correct 118 ms 19980 KB Output is correct
43 Correct 79 ms 19964 KB Output is correct
44 Incorrect 0 ms 2396 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -