Submission #328320

# Submission time Handle Problem Language Result Execution time Memory
328320 2020-11-16T06:19:02 Z arnold518 Ancient Books (IOI17_books) C++14
0 / 100
1 ms 512 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;

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

const int MAXN = 1e6;

int N;
int A[MAXN+10], B[MAXN+10], S;
ll ans;

ll minimum_walk(vector<int> _P, int _S)
{
	N=_P.size(); S=_S+1;
	for(int i=1; i<=N; i++) A[i]=_P[i-1]+1;
	for(int i=1; i<=N; i++) B[A[i]]=i;

	for(int i=1; i<=N; i++) ans+=abs(i-A[i]);

	vector<pii> V;
	for(int i=1; i<=N; i++)
	{
		int l=min(i, A[i]), r=max(i, A[i]);
		V.push_back({l, r});
	}

	sort(V.begin(), V.end());
	int p=0, q=0;
	vector<pii> VV;

	for(auto it : V)
	{
		if(q<it.first)
		{
			VV.push_back({p, q});
			p=it.first; q=it.second;
		}
		q=it.second;
	}
	if(p) VV.push_back({p, q});

	ans+=(VV.size()-1)*2;
	for(int i=0; i<VV.size() && VV[i].first==VV[i].second && VV[i].second<S; i++) ans-=2;
	for(int i=VV.size()-2; i>=0 && VV[i].first==VV[i].second && VV[i].first>S; i--) ans-=2;
	return ans;
}

Compilation message

books.cpp: In function 'll minimum_walk(std::vector<int>, int)':
books.cpp:46:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |  for(int i=0; i<VV.size() && VV[i].first==VV[i].second && VV[i].second<S; i++) ans-=2;
      |               ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Incorrect 1 ms 364 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 1 ms 364 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Incorrect 1 ms 364 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 1 ms 364 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Incorrect 1 ms 364 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 492 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4080'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Incorrect 1 ms 364 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -