Submission #390495

# Submission time Handle Problem Language Result Execution time Memory
390495 2021-04-16T07:52:05 Z Keshi Ancient Books (IOI17_books) C++17
0 / 100
2000 ms 332 KB
//In the name of God
#include <bits/stdc++.h>
#include "books.h"
using namespace std;

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

const ll maxn = 2e5 + 100;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

#define pb push_back
#define Mp make_pair
#define F first
#define S second
#define Sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()

ll a[maxn], b[maxn];

long long minimum_walk(vector<int> p, int s){
	ll n = Sz(p);
	for(ll i = 0; i < n; i++){
		if(p[i] > i){
			a[i]++;
			a[p[i]]--;
		}
		else{
			b[p[i]]++;
			b[i]--;
		}
	}
	for(ll i = 1; i < n; i++){
		a[i] += a[i - 1];
		b[i] += b[i - 1];
	}
	ll r = n;
	while(r && p[r - 1] == r - 1) r--;
	ll l = 0;
	while(l < n && p[l] == l) l;
	l = min(l, ll(s));
	r = max(r, s + 1ll);
	ll ans = 0;
	for(ll i = l; i < r - 1; i++){
		ans += max(1ll, max(a[i], b[i]));
	}
	return ans * 2;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:41:28: warning: statement has no effect [-Wunused-value]
   41 |  while(l < n && p[l] == l) l;
      |                            ^
# Verdict Execution time Memory Grader output
1 Execution timed out 2076 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2076 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2076 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 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 Execution timed out 2076 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -