Submission #42479

# Submission time Handle Problem Language Result Execution time Memory
42479 2018-02-27T16:07:43 Z yusufake Ancient Books (IOI17_books) C++
0 / 100
2 ms 352 KB
#include<bits/stdc++.h>
 
using namespace std;
 
#define _   int v, int tl, int tr, int l, int r
#define tm  (tl+tr >> 1)
#define sol v+v,tl,tm,l,r
#define sag v+v+1,tm+1,tr,l,r
 
#define mp make_pair
#define pb push_back
#define st first
#define nd second
 
typedef long long ll;
typedef pair < ll , ll > pp;
 
const int mod = 1e9 + 7;
const int N   = 1e6 + 6;
 
ll H[N],A[N],n,i,j,l,r,t,x,a,b;
 
ll minimum_walk(vector < int > p , int s){
    x = t = a = b = 0;
	n = p.size();
    for(i=0;i<n;i++) H[i] = A[i] = 0;
	for(i=0;i<n;i++){
		x += abs(p[i] - i);
		if(H[i]) continue;
		l = r = i;
		for(j=i; !H[j] ; j = p[j]){
			H[j] = 1;
			l = min(l , j);
			r = max(r , j);
		}
		A[l] = r;
	}
    return x;
	for(t=r=-1,i=0;i<n;i++){
		if(i > r) t++;
        r = max(r , A[i]);
    }
    
    for(i=0;i<n && p[i] == i; i++) a++;
    for(j=n-1;j>=0 && p[j] == j; j--) b++;
        return x + t+t;
    if(i == n) return 0;
    else if(s < i) t -= b+s;
    else if(s > j) t -= a+n-1-s;
    else t -= a+b;
    return x + 2 * t;
    
}	
/*
int main(){
    cout << minimum_walk({1,0,2,3} , 2);
}
*/
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 248 KB 3rd lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 248 KB 3rd lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 248 KB 3rd lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 352 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 Incorrect 1 ms 248 KB 3rd lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -