답안 #977356

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
977356 2024-05-07T19:17:42 Z mariaclara 고대 책들 (IOI17_books) C++17
0 / 100
1 ms 348 KB
#include "books.h"
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define mk make_pair
#define pb push_back
#define fr first
#define sc second

ll minimum_walk(vector<int> p, int s) {
	int n = sz(p);
	vector<bool> vis(n);
	vector<pii> range;

	ll ans;
	for(int i = 0; i < n; i++) {
		int x = i, m = i;
		while(!vis[x]) {
			vis[x] = 1;
			x = p[x];
			m = max(m, x);
		}

		ans += abs(p[i]-i);
		if(i != m) range.pb({i,m});
	}

	int L = 0;
	for(int i = 0; i < sz(range);) {
		int l = range[i].fr, r = range[i].sc, j = i;
		while(j < sz(range) and range[j].fr < r) {
			r = max(r, range[j].sc);
			j++;
		}
		i=j;
		L = l;
	}

	return ans + 2*L;
}

Compilation message

books.cpp: In function 'll minimum_walk(std::vector<int>, int)':
books.cpp:34:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |  for(int i = 0; i < sz(range);) {
      |                   ^
books.cpp:36: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]
   36 |   while(j < sz(range) and range[j].fr < r) {
      |           ^
books.cpp:44:17: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   44 |  return ans + 2*L;
      |                 ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '6', found: '140732440502598'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '6', found: '140732440502598'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '6', found: '140732440502598'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '3304', found: '140733152770888'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '6', found: '140732440502598'
2 Halted 0 ms 0 KB -