# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
46037 |
2018-04-17T03:41:33 Z |
RockyB |
Robots (APIO13_robots) |
C++14 |
|
91 ms |
95284 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 + 1;
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];
short dp[1 << 9][N][N];
struct node {
short mask, x, y;
node() {}
node(short mask, short x, short y) : mask(mask), x(x), y(y) {}
};
vector <node> q[N * N];
bool check(short x, short y) {
return 1 <= x && x <= n && 1 <= y && y <= m && a[x][y] != 'x';
}
pair <short, short> res[N][N][4];
bool was[N][N][4];
pair <short, short> go(short x, short y, short t) {
if (a[x][y] == 'C') t = (t + 1) % 4;
if (a[x][y] == 'A') t = (((t - 1) + 4) % 4);
if (was[x][y][t]) return res[x][y][t];
was[x][y][t] = 1;
if (check(x + dx[t], y + dy[t])) return res[x][y][t] = go(x + dx[t], y + dy[t], t);
return res[x][y][t] = {x, y};
}
vector <int> good[1 << 9];
ll calc() {
ll total = 0;
for (int mask = 0; mask < (1 << 9); mask++) {
for (int x = 1; x <= 300; x++) {
for (int y = 1; y <= 300; y++) {
for (auto to : good[mask]) {
total += 4;
}
}
}
}
return total;
}
int main() {
#ifdef IOI2018
freopen ("in.txt", "r", stdin);
#endif
//cout << (2 * sizeof(dp) + sizeof(res) + sizeof(was) + sizeof(a)) / sqr(1024);
//ioi
Kazakhstan
cin >> h >> m >> n;
memset(dp, 0x3f, sizeof(dp));
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;
q[0].pb(node(1 << x, i, j));
}
dp[0][i][j] = 0;
}
}
{
for (int mask = 0; mask < (1 << h); mask++) {
for (int to = 0; to < (1 << h); to++) {
if (!(mask & to)) good[mask].pb(to);
}
}
}
memset(res, -1, sizeof(res));
for (int cur = 0; cur <= 0x3f; cur++) {
for (auto v : q[cur]) {
for (auto mask : good[v.mask]) {
for (int i = 0; i < 4; i++) {
pair <short, short> to = go(v.x, v.y, i);
if (to.f == -1) continue;
short nxt = mask | v.mask, cost = cur + dp[mask][to.f][to.s] + 1;
if (dp[nxt][to.f][to.s] > cost) {
//st.erase({cost, nxt, to.f, to.s});
dp[nxt][to.f][to.s] = cost;
q[cost].pb(node(nxt, to.f, to.s));
}
}
}
}
q[cur].clear();
}
short ans = 0x3f;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
ans = min(ans, dp[(1 << h) - 1][i][j]);
}
}
if (ans >= 0x3f) ans = -1;
cout << ans;
ioi
}
Compilation message
robots.cpp: In function 'll calc()':
robots.cpp:74:15: warning: unused variable 'to' [-Wunused-variable]
for (auto to : good[mask]) {
^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
94712 KB |
Output is correct |
2 |
Correct |
72 ms |
94712 KB |
Output is correct |
3 |
Correct |
69 ms |
94748 KB |
Output is correct |
4 |
Correct |
71 ms |
94852 KB |
Output is correct |
5 |
Correct |
70 ms |
94932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
94712 KB |
Output is correct |
2 |
Correct |
72 ms |
94712 KB |
Output is correct |
3 |
Correct |
69 ms |
94748 KB |
Output is correct |
4 |
Correct |
71 ms |
94852 KB |
Output is correct |
5 |
Correct |
70 ms |
94932 KB |
Output is correct |
6 |
Correct |
71 ms |
94932 KB |
Output is correct |
7 |
Correct |
73 ms |
94932 KB |
Output is correct |
8 |
Correct |
80 ms |
94932 KB |
Output is correct |
9 |
Correct |
70 ms |
94932 KB |
Output is correct |
10 |
Correct |
78 ms |
94956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
94712 KB |
Output is correct |
2 |
Correct |
72 ms |
94712 KB |
Output is correct |
3 |
Correct |
69 ms |
94748 KB |
Output is correct |
4 |
Correct |
71 ms |
94852 KB |
Output is correct |
5 |
Correct |
70 ms |
94932 KB |
Output is correct |
6 |
Correct |
71 ms |
94932 KB |
Output is correct |
7 |
Correct |
73 ms |
94932 KB |
Output is correct |
8 |
Correct |
80 ms |
94932 KB |
Output is correct |
9 |
Correct |
70 ms |
94932 KB |
Output is correct |
10 |
Correct |
78 ms |
94956 KB |
Output is correct |
11 |
Incorrect |
91 ms |
95284 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
94712 KB |
Output is correct |
2 |
Correct |
72 ms |
94712 KB |
Output is correct |
3 |
Correct |
69 ms |
94748 KB |
Output is correct |
4 |
Correct |
71 ms |
94852 KB |
Output is correct |
5 |
Correct |
70 ms |
94932 KB |
Output is correct |
6 |
Correct |
71 ms |
94932 KB |
Output is correct |
7 |
Correct |
73 ms |
94932 KB |
Output is correct |
8 |
Correct |
80 ms |
94932 KB |
Output is correct |
9 |
Correct |
70 ms |
94932 KB |
Output is correct |
10 |
Correct |
78 ms |
94956 KB |
Output is correct |
11 |
Incorrect |
91 ms |
95284 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |