답안 #975267

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
975267 2024-05-04T16:18:21 Z StefanSebez 고대 책들 (IOI17_books) C++14
12 / 100
1 ms 500 KB
#include "books.h"
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define ll long long
long long minimum_walk(std::vector<int> p, int s){
	int n=p.size();ll res=0;
	ll a[n+10]={0};
	bool was[n+10]={0};
	int ctdobri=0;
	for(int i=0;i<n;i++){
		if(was[i]==true) continue;
		int j=p[i],ct=abs(p[i]-i);
		while(j!=i){
			ct+=abs(p[j]-j);
			was[j]=true;
			j=p[j];
		}
		/*j=p[i];
		while(j!=i){
			a[j]=ct;
			j=p[j];
		}*/
		a[i]=ct;
	}
	for(int i=0;i<n;i++){
		was[i]=false;
		if(p[i]==i) {ctdobri++;was[i]=true;}
	}
	int nesto=-10;
	for(int i=n-1;i>=0;i--){
		if(p[i]!=i) {nesto=i;break;}
	}
	//for(int i=0;i<n;i++) printf("%lld ",a[i]);
	//printf("\n");
	for(int i=0,maks=-1;i<n;i++){
		res++;
		if(maks>=i) res--;
		if(ctdobri==n) break;
		//printf("%i: %lld %i\n",i,res,maks);
		if(was[i]==true) continue;
		ctdobri++;
		was[i]=true;
		int j=p[i];
		maks=max(maks,i);
		while(j!=i){
			maks=max(maks,j);
			ctdobri++;
			was[j]=true;
			j=p[j];
		}
		res+=a[i];
		//printf("%i: %lld %i\n",i,res,maks);
		if(maks==nesto) {res+=i;maks=n;}
	}
	res--;
	/*for(int i=0;i<n;i++){
		int j=i;
		int trenutni=p[i];
		while(1){
			if(trenutni==j){
				trenutni=p[j];
				p[j]=j;
				if(j==i) break;
			}
			res++;
			if(trenutni>j) j++;
			else j--;
		}
		p[j]=trenutni;
		p[i]=i;
		//res+=2*(j-i);
		res++;
		//for(int k=0;k<n;k++) printf("%i ",p[k]);
		//printf("\n");
		bool sortirano=true;
		for(int k=1;k<n;k++){
			if(p[k-1]>p[k]) sortirano=false;
		}
		if(sortirano) break;
		res++;
	}
	res--;*/
	return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 500 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 500 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Incorrect 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '338572', found: '338575'
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 500 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Incorrect 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '338572', found: '338575'
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 500 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Incorrect 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '338572', found: '338575'
20 Halted 0 ms 0 KB -