Submission #1037034

# Submission time Handle Problem Language Result Execution time Memory
1037034 2024-07-27T22:34:59 Z ALeonidou Ancient Books (IOI17_books) C++17
0 / 100
0 ms 432 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 r = 0, e = 0;
	vis.assign(n, 0);
	dfs(0, r);
	for (ll i =0; i<n; 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 1 2 3

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;
      |     ^
# Verdict Execution time Memory 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 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 432 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 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 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -