Submission #307581

# Submission time Handle Problem Language Result Execution time Memory
307581 2020-09-28T16:57:40 Z CaroLinda Ancient Books (IOI17_books) C++14
0 / 100
1 ms 512 KB
#include "books.h"
#include <bits/stdc++.h>

#define debug printf
#define lp(i,a,b) for(int i = a ; i < b; i++)
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define pii pair<int,int>
#define ll long long 
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x.size())

using namespace std ;

long long minimum_walk(vector<int> p, int S) 
{

	assert( S == 0 ) ;

	int n = sz(p) ;
	long long ans = 0 ;
	int l , r ;

	for(l = 0 ; l < n ; l++ )
	{
		if(p[l] == l)
			ans += 2LL ;
		else break ;
	}

	if(l == n) return 0 ;

	for(r = n-1 ; r>= 0 ; r-- )
		if( p[r] != r ) break ;

	set<int> s ;
	s.insert( p[l] ) ;

	for(int i = l+1 ; i <= r ; i++ )
	{

		while( sz(s) )
		{
			auto it = s.begin() ;

			if( *it <= i-1 ) s.erase(it) ;
			else break ;
		}

		//Sobre a aresta i-1 -> i
		ans += min(2LL, 2LL*sz(s) ) ;
		s.insert( p[i] ) ;

	}

	return ans ;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Incorrect 1 ms 384 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Incorrect 1 ms 384 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Incorrect 1 ms 384 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Incorrect 1 ms 384 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
4 Halted 0 ms 0 KB -