답안 #428408

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
428408 2021-06-15T11:26:40 Z jeqcho 고대 책들 (IOI17_books) C++17
12 / 100
2000 ms 292 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define F0R(i,b) FOR(i,0,b)
#define ROF(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define R0F(i,b) ROF(i,0,b)
#define all(x) begin(x),end(x)
#define pb push_back
#define trav(a,x) for(auto&a:x)
#define sz(x) int(x.size())

vi p;
int n;
ll ans=1e18;

bool ok(int now)
{
	if(now!=0)return 0;
	F0R(i,n)
	{
		if(p[i]!=i)return 0;
	}
	return 1;
}
	

void go(int now,int cur,ll d,int cnt)
{
	if(now<0||now>=n)return;
	if(cnt>6)return;
	if(ok(now))
	{
		ans=min(ans,d);
		return;
	}
	FOR(i,-n,n)
	{
		go(now+i,cur,d+abs(i),cnt+1);
	}
	swap(cur,p[now]);
	FOR(i,-n,n)
	{
		go(now+i,cur,d+abs(i),cnt+1);
	}
	swap(cur,p[now]);
}

ll minimum_walk(vi p1, int s) {
	n=sz(p1);
	p=p1;
	go(0,-1,0,0);
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 284 KB Output is correct
2 Correct 23 ms 292 KB Output is correct
3 Correct 23 ms 284 KB Output is correct
4 Correct 3 ms 204 KB Output is correct
5 Correct 21 ms 204 KB Output is correct
6 Correct 21 ms 204 KB Output is correct
7 Correct 21 ms 204 KB Output is correct
8 Correct 21 ms 288 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 22 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 21 ms 284 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 22 ms 284 KB Output is correct
16 Correct 25 ms 204 KB Output is correct
17 Correct 22 ms 284 KB Output is correct
18 Correct 24 ms 288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 284 KB Output is correct
2 Correct 23 ms 292 KB Output is correct
3 Correct 23 ms 284 KB Output is correct
4 Correct 3 ms 204 KB Output is correct
5 Correct 21 ms 204 KB Output is correct
6 Correct 21 ms 204 KB Output is correct
7 Correct 21 ms 204 KB Output is correct
8 Correct 21 ms 288 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 22 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 21 ms 284 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 22 ms 284 KB Output is correct
16 Correct 25 ms 204 KB Output is correct
17 Correct 22 ms 284 KB Output is correct
18 Correct 24 ms 288 KB Output is correct
19 Execution timed out 2065 ms 204 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 284 KB Output is correct
2 Correct 23 ms 292 KB Output is correct
3 Correct 23 ms 284 KB Output is correct
4 Correct 3 ms 204 KB Output is correct
5 Correct 21 ms 204 KB Output is correct
6 Correct 21 ms 204 KB Output is correct
7 Correct 21 ms 204 KB Output is correct
8 Correct 21 ms 288 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 22 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 21 ms 284 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 22 ms 284 KB Output is correct
16 Correct 25 ms 204 KB Output is correct
17 Correct 22 ms 284 KB Output is correct
18 Correct 24 ms 288 KB Output is correct
19 Execution timed out 2065 ms 204 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2047 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 284 KB Output is correct
2 Correct 23 ms 292 KB Output is correct
3 Correct 23 ms 284 KB Output is correct
4 Correct 3 ms 204 KB Output is correct
5 Correct 21 ms 204 KB Output is correct
6 Correct 21 ms 204 KB Output is correct
7 Correct 21 ms 204 KB Output is correct
8 Correct 21 ms 288 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 22 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 21 ms 284 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 22 ms 284 KB Output is correct
16 Correct 25 ms 204 KB Output is correct
17 Correct 22 ms 284 KB Output is correct
18 Correct 24 ms 288 KB Output is correct
19 Execution timed out 2065 ms 204 KB Time limit exceeded
20 Halted 0 ms 0 KB -