답안 #73447

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
73447 2018-08-28T09:24:11 Z SmsS 고대 책들 (IOI17_books) C++14
22 / 100
2000 ms 12340 KB
#include<bits/stdc++.h>
using namespace std;
#define for2(a,b,c) for(int a = b; a < c; a++)
#include "books.h"
#define ll long long

const int maxn =  1000100;
int par[maxn];

int getpar(int x){
	if(par[x] < 0) return x;
	return par[x] = getpar(par[x]);
}

long long minimum_walk(std::vector<int> p, int s) {
//	if(s != 0) return 0;
	ll res = 0;
	int n = p.size();
	fill(par,par+n,-1);
	for2(i,0,n) res += abs(i-p[i]);
	int cnt = 0;
	for2(i,0,n){
		int l = min(i,p[i]);
		int r = max(i,p[i]);
		for2(j,l,r+1){
			int x = getpar(i);
			int y = getpar(j);
			if(x != y){
				if(par[x] < par[y]) swap(x,y);
				par[y] += par[x];
				par[x] = y;
			}
		}
	}
	for2(i,0,n) if(getpar(i) == i) res += 2;
	res -= 2;
	for(int i = n-1; i > s; i--){
		if(par[getpar(i)] != -1) break;
		res -= 2;
	}
	for2(i,0,n){

		if(par[getpar(i)] != -1 || i == s) break;
		res -= 2;
	}
	return res;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:21:6: warning: unused variable 'cnt' [-Wunused-variable]
  int cnt = 0;
      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 508 KB Output is correct
3 Correct 4 ms 508 KB Output is correct
4 Correct 3 ms 508 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 2 ms 508 KB Output is correct
7 Correct 3 ms 508 KB Output is correct
8 Correct 2 ms 508 KB Output is correct
9 Correct 2 ms 508 KB Output is correct
10 Correct 2 ms 508 KB Output is correct
11 Correct 2 ms 540 KB Output is correct
12 Correct 4 ms 540 KB Output is correct
13 Correct 2 ms 540 KB Output is correct
14 Correct 3 ms 540 KB Output is correct
15 Correct 2 ms 540 KB Output is correct
16 Correct 2 ms 540 KB Output is correct
17 Correct 3 ms 540 KB Output is correct
18 Correct 2 ms 540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 508 KB Output is correct
3 Correct 4 ms 508 KB Output is correct
4 Correct 3 ms 508 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 2 ms 508 KB Output is correct
7 Correct 3 ms 508 KB Output is correct
8 Correct 2 ms 508 KB Output is correct
9 Correct 2 ms 508 KB Output is correct
10 Correct 2 ms 508 KB Output is correct
11 Correct 2 ms 540 KB Output is correct
12 Correct 4 ms 540 KB Output is correct
13 Correct 2 ms 540 KB Output is correct
14 Correct 3 ms 540 KB Output is correct
15 Correct 2 ms 540 KB Output is correct
16 Correct 2 ms 540 KB Output is correct
17 Correct 3 ms 540 KB Output is correct
18 Correct 2 ms 540 KB Output is correct
19 Correct 4 ms 688 KB Output is correct
20 Correct 5 ms 688 KB Output is correct
21 Correct 3 ms 688 KB Output is correct
22 Correct 3 ms 688 KB Output is correct
23 Correct 3 ms 688 KB Output is correct
24 Correct 3 ms 688 KB Output is correct
25 Correct 3 ms 688 KB Output is correct
26 Correct 3 ms 688 KB Output is correct
27 Correct 2 ms 688 KB Output is correct
28 Correct 4 ms 688 KB Output is correct
29 Correct 3 ms 688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 508 KB Output is correct
3 Correct 4 ms 508 KB Output is correct
4 Correct 3 ms 508 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 2 ms 508 KB Output is correct
7 Correct 3 ms 508 KB Output is correct
8 Correct 2 ms 508 KB Output is correct
9 Correct 2 ms 508 KB Output is correct
10 Correct 2 ms 508 KB Output is correct
11 Correct 2 ms 540 KB Output is correct
12 Correct 4 ms 540 KB Output is correct
13 Correct 2 ms 540 KB Output is correct
14 Correct 3 ms 540 KB Output is correct
15 Correct 2 ms 540 KB Output is correct
16 Correct 2 ms 540 KB Output is correct
17 Correct 3 ms 540 KB Output is correct
18 Correct 2 ms 540 KB Output is correct
19 Correct 4 ms 688 KB Output is correct
20 Correct 5 ms 688 KB Output is correct
21 Correct 3 ms 688 KB Output is correct
22 Correct 3 ms 688 KB Output is correct
23 Correct 3 ms 688 KB Output is correct
24 Correct 3 ms 688 KB Output is correct
25 Correct 3 ms 688 KB Output is correct
26 Correct 3 ms 688 KB Output is correct
27 Correct 2 ms 688 KB Output is correct
28 Correct 4 ms 688 KB Output is correct
29 Correct 3 ms 688 KB Output is correct
30 Execution timed out 2057 ms 12340 KB Time limit exceeded
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 12340 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 508 KB Output is correct
3 Correct 4 ms 508 KB Output is correct
4 Correct 3 ms 508 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 2 ms 508 KB Output is correct
7 Correct 3 ms 508 KB Output is correct
8 Correct 2 ms 508 KB Output is correct
9 Correct 2 ms 508 KB Output is correct
10 Correct 2 ms 508 KB Output is correct
11 Correct 2 ms 540 KB Output is correct
12 Correct 4 ms 540 KB Output is correct
13 Correct 2 ms 540 KB Output is correct
14 Correct 3 ms 540 KB Output is correct
15 Correct 2 ms 540 KB Output is correct
16 Correct 2 ms 540 KB Output is correct
17 Correct 3 ms 540 KB Output is correct
18 Correct 2 ms 540 KB Output is correct
19 Correct 4 ms 688 KB Output is correct
20 Correct 5 ms 688 KB Output is correct
21 Correct 3 ms 688 KB Output is correct
22 Correct 3 ms 688 KB Output is correct
23 Correct 3 ms 688 KB Output is correct
24 Correct 3 ms 688 KB Output is correct
25 Correct 3 ms 688 KB Output is correct
26 Correct 3 ms 688 KB Output is correct
27 Correct 2 ms 688 KB Output is correct
28 Correct 4 ms 688 KB Output is correct
29 Correct 3 ms 688 KB Output is correct
30 Execution timed out 2057 ms 12340 KB Time limit exceeded
31 Halted 0 ms 0 KB -