Submission #400691

# Submission time Handle Problem Language Result Execution time Memory
400691 2021-05-08T14:02:36 Z BERNARB01 Bali Sculptures (APIO15_sculpture) C++17
0 / 100
1 ms 1104 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 10;
const int inf = 1e5 + 9;

int n, m, target, b[N], p[N], dp[N][N][2][1 << N];
vector<int> g[N];

int sol(int i, int j, int dir, int vis) {
	if (i == target) {
		return 0;
	}
	int& ret = dp[i][j][dir][vis];
	if (ret != -1) {
		return ret;
	}
	ret = inf;
	int new_v = vis | (1 << i);
	if (dir) {
		if (i + p[j] < n) {
			ret = min(ret, 1 + sol(i + p[j], j, dir, new_v));
		}
	} else {
		if (i - p[j] >= 0) {
			ret = min(ret, 1 + sol(i - p[j], j, dir, new_v));
		}
	}
	for (int new_j : g[i]) {
		ret = min(ret, sol(i, new_j, 1, new_v));
		ret = min(ret, sol(i, new_j, 0, new_v));
	}
	return ret;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> b[i] >> p[i];
		g[b[i]].push_back(i);
	}
	target = b[1];
	memset(dp, -1, sizeof dp);
	cout << sol(0, 0, 1, 0) << '\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1104 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1104 KB Output isn't correct
2 Halted 0 ms 0 KB -