답안 #1045338

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1045338 2024-08-05T20:42:11 Z beaconmc 고대 책들 (IOI17_books) C++14
50 / 100
152 ms 43444 KB
#include "books.h"

#include <bits/stdc++.h>

 
typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
 
using namespace std;


long long minimum_walk(vector<int> p, int s) {

	vector<int> q;
	for (auto&i : p)q.push_back(i);
	sort(q.begin(), q.end());
	if (p==q) return 0;
	vector<bool> visited;
	vector<ll> maxis;
	for (auto&i : p) visited.push_back(0), maxis.push_back(-1);

	FOR(i,0,p.size()){
		vector<ll> stuff;
		ll temp = i;
		ll maxi = i;
		if (visited[temp]) continue;
		visited[temp] = 1;
		temp = p[temp];
		stuff.push_back(temp);
		while (temp != i){
			maxi = max(maxi, temp);
			visited[temp] = 1;
			temp = p[temp];
			visited[temp] = 1;
			stuff.push_back(temp);
		}
		for (auto&k : stuff){
			maxis[k] = maxi;
		}
	}


	ll cur = 0;
	ll ans = 0;
	FOR(i,0,p.size()){
		ans += abs(p[i]-i);
	}
	ll hi = p.size()-1;
	while (p[hi]==hi) hi--;




	while (cur < p.size()-1){
		if (cur >= hi) break;
		if (cur == maxis[cur]){
			ans+=2, cur++;
		}
		else{
			FOR(i,cur,maxis[cur]+1){
				cur = max(cur,maxis[i]);
			}
		}
	}


	return ans;

}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:21:12: warning: unused variable 'i' [-Wunused-variable]
   21 |  for (auto&i : p) visited.push_back(0), maxis.push_back(-1);
      |            ^
books.cpp:7:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 | #define FOR(i,x,y) for(ll i=x; i<y; i++)
......
   23 |  FOR(i,0,p.size()){
      |      ~~~~~~~~~~~~                
books.cpp:23:2: note: in expansion of macro 'FOR'
   23 |  FOR(i,0,p.size()){
      |  ^~~
books.cpp:7:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 | #define FOR(i,x,y) for(ll i=x; i<y; i++)
......
   46 |  FOR(i,0,p.size()){
      |      ~~~~~~~~~~~~                
books.cpp:46:2: note: in expansion of macro 'FOR'
   46 |  FOR(i,0,p.size()){
      |  ^~~
books.cpp:55:13: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |  while (cur < p.size()-1){
      |         ~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 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 0 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 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 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 348 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 0 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 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 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 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 600 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 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 360 KB Output is correct
26 Correct 0 ms 348 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 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 0 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 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 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 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 600 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 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 360 KB Output is correct
26 Correct 0 ms 348 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 348 KB Output is correct
30 Correct 152 ms 43444 KB Output is correct
31 Correct 148 ms 34232 KB Output is correct
32 Correct 68 ms 20676 KB Output is correct
33 Correct 124 ms 32972 KB Output is correct
34 Correct 97 ms 31320 KB Output is correct
35 Correct 106 ms 32976 KB Output is correct
36 Correct 99 ms 32608 KB Output is correct
37 Correct 98 ms 32952 KB Output is correct
38 Correct 106 ms 31300 KB Output is correct
39 Correct 107 ms 32444 KB Output is correct
40 Correct 124 ms 32184 KB Output is correct
41 Correct 134 ms 33476 KB Output is correct
42 Correct 132 ms 32212 KB Output is correct
43 Correct 97 ms 31676 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 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 0 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 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 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 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 600 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 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 360 KB Output is correct
26 Correct 0 ms 348 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 348 KB Output is correct
30 Correct 152 ms 43444 KB Output is correct
31 Correct 148 ms 34232 KB Output is correct
32 Correct 68 ms 20676 KB Output is correct
33 Correct 124 ms 32972 KB Output is correct
34 Correct 97 ms 31320 KB Output is correct
35 Correct 106 ms 32976 KB Output is correct
36 Correct 99 ms 32608 KB Output is correct
37 Correct 98 ms 32952 KB Output is correct
38 Correct 106 ms 31300 KB Output is correct
39 Correct 107 ms 32444 KB Output is correct
40 Correct 124 ms 32184 KB Output is correct
41 Correct 134 ms 33476 KB Output is correct
42 Correct 132 ms 32212 KB Output is correct
43 Correct 97 ms 31676 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 -