Submission #581788

# Submission time Handle Problem Language Result Execution time Memory
581788 2022-06-23T06:23:36 Z alireza_kaviani Ancient Books (IOI17_books) C++17
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>
#include "books.h"
using namespace std;

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

#define sep			' '
#define X			first
#define Y			second
#define all(x)		(x).begin() , (x).end()
#define SZ(x)		int(x.size())

const int MAXN = 1e6 + 10;

ll n , s , sum , P[MAXN] , mark[MAXN];

ll minimum_walk(vector<int> p, int S) {
	n = SZ(p); s = S;
	for(int i = 0 ; i < n ; i++){
		P[i] = p[i];
		sum += abs(P[i] - i);
	}
	vector<pii> vec;
	for(int i = 0 ; i < n ; i++){
		if(!mark[i]){
			int mn = MAXN , mx = 0 , x = i;
			while(!mark[x]){
				mark[x] = 1;
				mn = min(mn , x);
				mx = max(mx , x);
				x = P[x];
			}
			vec.push_back({mn , mx});
		}
	}
	sort(all(vec));
	vector<int> comps;
	for(pii i : vec){
		if(SZ(comps) == 0 || comps.back() < i.X){
			comps.push_back(i.Y);
		}
		else{
			comps[SZ(comps) - 1] = max(comps.back() , i.Y);
		}
	}

	return sum + SZ(comps);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '8', found: '9'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '8', found: '9'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '8', found: '9'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2745'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '8', found: '9'
4 Halted 0 ms 0 KB -