답안 #828394

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
828394 2023-08-17T09:11:41 Z tolbi 고대 책들 (IOI17_books) C++17
50 / 100
304 ms 24900 KB
#include <bits/stdc++.h>
using namespace std;
#include "books.h"
long long minimum_walk(std::vector<int> p, int s) {
	int n = p.size();
	vector<bool> vis(n,false);
	vector<pair<int,int>> hehe;
	for (int i = 0; i < n; i++){
		if (vis[i]) continue;
		int node = i;
		if (p[node]==node) continue;
		while (!vis[node]){
			vis[node]=true;
			hehe.push_back({min(node,p[node]),1});
			hehe.push_back({max(node,p[node]),-1});
			node=p[node];
		}
	}
	sort(hehe.begin(), hehe.end());
	long long ans = 0;
	int crr = 0;
	int indi = 0;
	for (int i = s; i < n-1; i++){
		while (indi<hehe.size() && hehe[indi].first<=i){
			crr+=hehe[indi].second;
			indi++;
		}
		if (indi!=hehe.size() && crr==0){
			ans+=2;
		}
		if (crr>0) ans+=crr;
	}

	sort(hehe.rbegin(), hehe.rend());
	crr = 0;
	indi = 0;
	for (int i = s; i >= 0; i--){
		while (indi<hehe.size() && hehe[indi].first>=i){
			crr-=hehe[indi].second;
			indi++;
		}
		if (indi!=hehe.size() && crr==0){
			ans+=2;
		}
		if (crr>0) ans+=crr;
	}
	return ans;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:24:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |   while (indi<hehe.size() && hehe[indi].first<=i){
      |          ~~~~^~~~~~~~~~~~
books.cpp:28:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |   if (indi!=hehe.size() && crr==0){
      |       ~~~~^~~~~~~~~~~~~
books.cpp:38:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |   while (indi<hehe.size() && hehe[indi].first>=i){
      |          ~~~~^~~~~~~~~~~~
books.cpp:42:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |   if (indi!=hehe.size() && crr==0){
      |       ~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 304 ms 24784 KB Output is correct
31 Correct 304 ms 24788 KB Output is correct
32 Correct 69 ms 8184 KB Output is correct
33 Correct 123 ms 16568 KB Output is correct
34 Correct 120 ms 16488 KB Output is correct
35 Correct 160 ms 24744 KB Output is correct
36 Correct 184 ms 24784 KB Output is correct
37 Correct 213 ms 24796 KB Output is correct
38 Correct 242 ms 24756 KB Output is correct
39 Correct 236 ms 24788 KB Output is correct
40 Correct 257 ms 24756 KB Output is correct
41 Correct 290 ms 24900 KB Output is correct
42 Correct 275 ms 24800 KB Output is correct
43 Correct 176 ms 16472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 304 ms 24784 KB Output is correct
31 Correct 304 ms 24788 KB Output is correct
32 Correct 69 ms 8184 KB Output is correct
33 Correct 123 ms 16568 KB Output is correct
34 Correct 120 ms 16488 KB Output is correct
35 Correct 160 ms 24744 KB Output is correct
36 Correct 184 ms 24784 KB Output is correct
37 Correct 213 ms 24796 KB Output is correct
38 Correct 242 ms 24756 KB Output is correct
39 Correct 236 ms 24788 KB Output is correct
40 Correct 257 ms 24756 KB Output is correct
41 Correct 290 ms 24900 KB Output is correct
42 Correct 275 ms 24800 KB Output is correct
43 Correct 176 ms 16472 KB Output is correct
44 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -