Submission #297019

# Submission time Handle Problem Language Result Execution time Memory
297019 2020-09-11T07:50:08 Z Trickster Ancient Books (IOI17_books) C++14
0 / 100
1 ms 360 KB
#include "books.h"
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;

#define N 100
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mod 1000000007
#define pii pair <int, int>
#define sz(a) int(a.size())
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
ll bigmod(ll a,ll e) {if(e==0)return 1;ll x=bigmod(a*a%mod,e>>1);return e&1?x*a%mod:x;}

int n;

long long minimum_walk(std::vector<int> p, int s) {
	n = p.size();

	int x = s, y = -1, ans = 0;
	for(int i = 0; i < n; i++) {
		if(y <= i && y != -1) {
			ans += abs(x-y);

			int a = p[x], b = y;

			y = a, p[x] = b, x = b;
		}

		if(i == n-1) {
			ans += abs(x);
			break;
		}

		ans += abs(i+1-x);

		if(y == -1 && p[x] != i) {
			y = p[x];
			swap(p[x], p[i+1]);
			p[x] = -1;
		} 
		else swap(y, p[i+1]);
		x = i+1;
	}

	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 360 KB Output is correct
3 Incorrect 1 ms 360 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 360 KB Output is correct
3 Incorrect 1 ms 360 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 360 KB Output is correct
3 Incorrect 1 ms 360 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 256 KB 3rd lines differ - on the 1st token, expected: '3304', found: '5155'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 360 KB Output is correct
3 Incorrect 1 ms 360 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
4 Halted 0 ms 0 KB -