Submission #1028897

# Submission time Handle Problem Language Result Execution time Memory
1028897 2024-07-20T10:06:34 Z DorostWef Ancient Books (IOI17_books) C++17
0 / 100
0 ms 344 KB
#include "books.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int N = 1000123;
bool vis[N];
int n;

long long minimum_walk(std::vector<int> p, int s) {
	long long ans = 0;
	n = (int)p.size();
	for (int i = 0; i < n; i++) {
		vis[i] = false;
	}
	for (int i = 0; i < n; i++) {
		ans += abs (p[i] - i);
	}
	int mx = 0;
	for (int i = 0; i < n; i++) {
		if (!vis[i]) {
			if (p[i] == i)
				continue;
			mx = i;
			int j = i;
			while (p[j] != i) {
				j = p[j];
				vis[j] = true;
			}
		}
	}
	return ans;// + 2 * mx;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:20:6: warning: variable 'mx' set but not used [-Wunused-but-set-variable]
   20 |  int mx = 0;
      |      ^~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 3rd lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 3rd lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 3rd lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 3rd lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -