Submission #804528

# Submission time Handle Problem Language Result Execution time Memory
804528 2023-08-03T09:34:18 Z Benmath Ancient Books (IOI17_books) C++14
12 / 100
1 ms 344 KB
#include "books.h"

#include <bits/stdc++.h>

using namespace std;
long long minimum_walk(std::vector<int> p, int s) {
	long long int sum=0;
	int n=p.size();
	int vis[n];
	for(int i=0;i<n;i++){
	    vis[i]=0;
	}
long long	int sad=0;
vector<pair<int,int> >v;
	for(int i=0;i<n;i++){
	    if(vis[i]==0 and i!=p[i]){
	        int maxi=i;
	        sad=i;
	        int i1=i;
	        int t1=0;
	        long long int iduci=p[i];
	        long long int tren=i;
	        while(t1==0){
	            sum=sum+abs(iduci-tren);
	            vis[tren]++;
	            if(tren>maxi){
	                maxi=tren;
	            }
	            tren=iduci;
	            iduci=p[tren];
	            if(tren==i1){
	                break;
	            }
	        }
	        v.push_back({i,maxi});
	    }
	}
	sad=0;
	for(int i=v.size()-1;i>=0;i--){
	    int x=v[i].first;
	    int t1=0;
	    for(int j=i-1;j>=0;j--){
	        if(v[j].first<=x and v[j].second>=x){
	            t1++;
	        }
	    }
	    if(t1==0){
	        sad=x;
	         break;
	    }
	}
	sum=sum+2*sad;
	return sum;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 296 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 0 ms 296 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 216 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 296 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 0 ms 296 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 216 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 300 KB Output is correct
21 Correct 1 ms 300 KB Output is correct
22 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '2082', found: '2782'
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 296 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 0 ms 296 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 216 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 300 KB Output is correct
21 Correct 1 ms 300 KB Output is correct
22 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '2082', found: '2782'
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 300 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 Correct 1 ms 300 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 296 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 0 ms 296 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 216 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 300 KB Output is correct
21 Correct 1 ms 300 KB Output is correct
22 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '2082', found: '2782'
23 Halted 0 ms 0 KB -