답안 #1037035

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1037035 2024-07-27T22:37:29 Z ALeonidou 고대 책들 (IOI17_books) C++17
50 / 100
101 ms 30692 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define endl "\n"
#define sz(x) (ll)x.size()
#define F first
#define S second
#define pb push_back
#define INF 1000000000000000000

typedef vector <ll> vi;
typedef pair <ll,ll> ii;
typedef vector <ii> vii;

#define dbg(x) cout<<#x<<": "<<x<<endl;
#define dbg2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl;
#define dbg3(x,y,z) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<" "<<#z<<": "<<z<<endl;

void printVct(vi &v){
	for (ll i =0; i<sz(v); i++){
		cout<<v[i]<<" ";
	}
	cout<<endl;
}

ll n;
vi p;

vi vis;
void dfs(ll u, ll &r){
	vis[u] =1;
	r = max(r,u);
	ll c = p[u];
	if (!vis[c]) dfs(c,r);
}

long long minimum_walk(vector<int> P, int ss) {
	n = sz(P);
	p.resize(n);
	for (ll i =0; i<n; i++){
		p[i] = P[i];
	}
	ll s = ss;

	ll d = 0;
	for (ll i =0; i<n; i++){
		d += abs(i - p[i]);
	}

	ll b = n-1;
	while (b >= 0 && p[b] == b) b--;

	ll r = 0, e = 0;
	vis.assign(n, 0);
	dfs(0, r);
	for (ll i =0; i<b; i++){
		if (r < i) e++;
		if (!vis[i]) dfs(i, r);
  	}

	ll ans = d + e * 2;
	return ans;
}

/*
4 0
0 2 3 1

4 0
0 2 3 1

4 0
3 2 1 0
*/

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:45:5: warning: unused variable 's' [-Wunused-variable]
   45 |  ll s = ss;
      |     ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 416 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 416 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 432 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 416 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 432 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 440 KB Output is correct
30 Correct 101 ms 30576 KB Output is correct
31 Correct 98 ms 30572 KB Output is correct
32 Correct 77 ms 30548 KB Output is correct
33 Correct 77 ms 30544 KB Output is correct
34 Correct 76 ms 30532 KB Output is correct
35 Correct 77 ms 30536 KB Output is correct
36 Correct 84 ms 30692 KB Output is correct
37 Correct 75 ms 30580 KB Output is correct
38 Correct 83 ms 30548 KB Output is correct
39 Correct 78 ms 30508 KB Output is correct
40 Correct 80 ms 30440 KB Output is correct
41 Correct 97 ms 30548 KB Output is correct
42 Correct 90 ms 30452 KB Output is correct
43 Correct 77 ms 30548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 416 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 432 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 440 KB Output is correct
30 Correct 101 ms 30576 KB Output is correct
31 Correct 98 ms 30572 KB Output is correct
32 Correct 77 ms 30548 KB Output is correct
33 Correct 77 ms 30544 KB Output is correct
34 Correct 76 ms 30532 KB Output is correct
35 Correct 77 ms 30536 KB Output is correct
36 Correct 84 ms 30692 KB Output is correct
37 Correct 75 ms 30580 KB Output is correct
38 Correct 83 ms 30548 KB Output is correct
39 Correct 78 ms 30508 KB Output is correct
40 Correct 80 ms 30440 KB Output is correct
41 Correct 97 ms 30548 KB Output is correct
42 Correct 90 ms 30452 KB Output is correct
43 Correct 77 ms 30548 KB Output is correct
44 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -