Submission #804538

# Submission time Handle Problem Language Result Execution time Memory
804538 2023-08-03T09:39:29 Z Benmath Ancient Books (IOI17_books) C++14
0 / 100
1 ms 212 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 maxi1=0;
	    int t1=0;
	    for(int j=i-1;j>=0;j--){
	        if(v[j].first<=x and v[j].second>=x){
	            t1++;
	        }
	        if(v[j].second>maxi1){
	            maxi1=v[j].second;
	        }
	    }
	    if(t1==0){
	        sum=sum+(x-maxi1);
	         
	    }
	}

	return sum;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:13:15: warning: variable 'sad' set but not used [-Wunused-but-set-variable]
   13 | long long int sad=0;
      |               ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 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 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -