Submission #982828

# Submission time Handle Problem Language Result Execution time Memory
982828 2024-05-14T19:14:09 Z Lalic Ancient Books (IOI17_books) C++17
0 / 100
1 ms 348 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e6+10;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int mark[MAXN];

pair<ll, int> dfs(vector<int>& p, int ver){
	mark[ver]=1;
	
	pair<ll, int> curr={abs(ver-p[ver]), max(ver, p[ver])};
	if(!mark[p[ver]]){
		pair<ll, int> temp=dfs(p, p[ver]);
		curr.fi+=temp.fi;
		curr.se=max(curr.se, temp.se);
	}
	
	return curr;
}

ll minimum_walk(vector<int> p, int s) {
	int n=(int)p.size();
	
	ll ans=0;
	vector<pii> proc;
	for(int i=0;i<n;i++){
		if(mark[i]) continue;
		pair<ll, int> temp=dfs(p, i);
		ans+=temp.fi;
		proc.pb({i, temp.se});
	}
	
	sort(all(proc));
	
	int last=0;
	for(auto u : proc){
		ans+=2ll*max(0ll, (ll)u.fi-(ll)last);
		last=max(last, u.se);
	}
	
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 1 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 344 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 1 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 344 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 1 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 1 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 Correct 0 ms 344 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 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -