Submission #790823

# Submission time Handle Problem Language Result Execution time Memory
790823 2023-07-23T08:34:19 Z fatemetmhr Ancient Books (IOI17_books) C++17
0 / 100
1 ms 312 KB
//  ~ Be Name Khoda ~  //

#include "books.h"
#include <bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops,Ofast")

using namespace std;

typedef long long ll;

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

const int maxn  =  1e6   + 10;
const int maxn5 =  1e6   + 10;
const int maxnt =  1.2e6 + 10;
const int maxn3 =  1e3   + 10;
const int mod   =  1e9   + 7;
const ll  inf   =  1e18;

ll ans = 0;
int per[maxn5];
int num = 0, av[maxn5];
bool mark[maxn5];

void dfs(int v){
	mark[v] = true;
	av[num] = min(av[num], v);
	ans += abs(v - per[v]);
	if(!mark[per[v]])
		dfs(per[v]);
}


long long minimum_walk(std::vector<int> p, int s) {
	int n = p.size();
	for(int i = 0; i < n; i++)
		per[i] = p[i];
	fill(av, av + n + 5, n + 10);
	int mx = 0;
	for(int i = 0; i < n; i++) if(!mark[i]){
		dfs(i);
		mx = max(mx, av[num]);
		num++;
	}
	return ans + 2 * mx;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 312 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4736'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -