답안 #1029042

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1029042 2024-07-20T11:37:14 Z amirhoseinfar1385 고대 책들 (IOI17_books) C++17
0 / 100
1 ms 2396 KB
#include"books.h"
#include <vector>
#include<bits/stdc++.h>
const int maxn=1000000+10;
using namespace std;
int vis[maxn],visa[maxn];
int n;

long long minimum_walk(std::vector<int> p, int s){
	n=p.size();
	for(int i=0;i<=n;i++){
		vis[i]=visa[i]=0;
	}
	long long mainres=0,last=0;
	int cnt1=0;
	for(int i=0;i<n;i++){
		if(p[i]>i){
			cnt1++;
			visa[p[i]]=1;
		}
		if(visa[i]){
			cnt1--;
		}
		mainres+=cnt1*2;
		if(cnt1!=0){
			last=i+1;
		}
	}
	for(int i=0;i<=last;i++){
		if(vis[i]==0){
			mainres+=2;
			int now=i;
			do{
				vis[now]=1;
				now=p[now];
			}while(now!=i);
		}
	}
	mainres-=2;
	return mainres;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 0 ms 2396 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 0 ms 2396 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 0 ms 2396 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2392 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4186'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 0 ms 2396 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -