Submission #45819

# Submission time Handle Problem Language Result Execution time Memory
45819 2018-04-16T08:26:55 Z RockyB Robots (APIO13_robots) C++17
0 / 100
2 ms 384 KB
/// In The Name Of God

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()

#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = (int)300 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

using namespace std;

int n, m, h;
char a[N][N];

int dp[1 << 9][N][N];

struct node {
	int cost, mask, x, y;
	node() {}
	node(int cost, int mask, int x, int y) : cost(cost), mask(mask), x(x), y(y) {}
	bool operator < (node r) const {
		if (cost != r.cost) return cost < r.cost;
		if (mask != r.mask) return mask < r.mask;
		if (x != r.x) return x < r.x;
		return y < r.y;
	}
};

bool check(int x, int y) {
	return 1 <= x && x <= n && 1 <= y && y <= m && a[x][y] != 'x';
}
pair <int, int> go(int x, int y, int t) {
	while (1) {
		if (check(x + dx[t], y + dy[t])) {
			x += dx[t], y += dy[t];
		}
		else break;
	}
	return {x, y};
}

int main() {
	#ifdef IOI2018
		freopen ("in.txt", "r", stdin);
	#endif
	Kazakhstan
	srand(time(0));
	cin >> h >> n >> m;
	memset(dp, 0x3f, sizeof(dp));

	set <node> st;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cin >> a[i][j];
			if (isdigit(a[i][j])) {
				int x = a[i][j] - '1';
				dp[1 << x][i][j] = 0;
				st.insert(node(0, 1 << x, i, j));
			}
		}
	}	

	while (sz(st)) {
		node v = *st.begin();
		st.erase(st.begin());
		for (int i = 0; i < 4; i++) {
			pair <int, int> to = go(v.x, v.y, i);
			for (int mask = 0; mask < (1 << h); mask++) {
				if (!(mask & v.mask)) {
					int nxt = mask | v.mask;
					if (dp[nxt][to.f][to.s] > v.cost + 1) {
						st.erase({v.cost + 1, nxt, to.f, to.s});
						dp[nxt][to.f][to.s] = v.cost + 1;
						st.insert({v.cost + 1, nxt, to.f, to.s});
					}
				}
			}
		}
	}

	int ans = inf;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			ans = min(ans, dp[(1 << h) - 1][i][j]);
		}
	}

	cout << ans;
	ioi
}
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -