# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
958564 |
2024-04-06T04:10:35 Z |
KasymK |
Robots (APIO13_robots) |
C++17 |
|
1500 ms |
16732 KB |
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define sz size()
#define ll long long
// yokary saga asak cepe
// 0 1 2 3
const int N = 505;
int aa[] = {-1, 0, 1, 0};
int bb[] = {0, 1, 0, -1};
pair <int, int> a1, b1;
int n, m, k, dis[N][N][N];
bool dur[N][N][4], vis[N][N][N];
char a[N][N];
vector <pair <int, int>> v;
pair <int, int> direct[N][N][4];
bool durmalymy (int x, int y) {
if (min (x, y) < 1 or x > n or y > m or a[x][y] == 'x') return 1;
return 0;
}
pair <int, int> ugur (int x, int y, int val) {
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
for (int k = 0; k < 4; ++k) {
dur[i][j][k] = 0;
}
}
}
while (1) {
if (a[x][y] == 'A') {
val--;
}
else if (a[x][y] == 'C') {
val++;
}
if (dur[x][y][val]) {
x = y = 0;
break;
}
val += 4;val %= 4;
dur[x][y][val] = 1;
if (durmalymy (x + aa[val], y + bb[val])) break;
x += aa[val];y += bb[val];
}
return {x, y};
}
int main () {
// freopen ("input.txt", "r", stdin);
cin >> k >> m >> n;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
cin >> a[i][j];
if (a[i][j] >= '1' and a[i][j] <= '9') v.pb ({i, j});
}
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
if (a[i][j] != 'x') {
for (int l = 0; l < 4; ++l) {
direct[i][j][l] = ugur(i, j, l);
}
}
}
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
for (int l = 1; l <= k; ++l) {
dis[i][j][l] = 1e9;
}
}
}
queue <pair <int, int>> q;
for (int j = 0; j < k; ++j) {
q.push({v[j].ff, v[j].ss});
dis[v[j].ff][v[j].ss][j + 1] = 0;
vis[0][0][j + 1] = vis[v[j].ff][v[j].ss][j + 1] = 1;
while (!q.empty()) {
auto op = q.front();
q.pop();
for (int i = 0; i < 4; ++i) {
auto x = direct[op.ff][op.ss][i];
if (vis[x.ff][x.ss][j + 1]) continue;
q.push({x.ff, x.ss});
dis[x.ff][x.ss][j + 1] = dis[op.ff][op.ss][j + 1] + 1;
vis[x.ff][x.ss][j + 1] = 1;
}
}
}
int jog = 1e9;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
ll sum = 0;
for (int l = 1; l <= k; ++l) {
sum += dis[i][j][l];
}
if (sum < (ll)1e9) jog = min (jog, (int)sum);
}
}
if (jog == 1e9) jog = -1;
cout << jog;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
2 ms |
8540 KB |
Output is correct |
4 |
Correct |
3 ms |
16732 KB |
Output is correct |
5 |
Correct |
2 ms |
16732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
2 ms |
8540 KB |
Output is correct |
4 |
Correct |
3 ms |
16732 KB |
Output is correct |
5 |
Correct |
2 ms |
16732 KB |
Output is correct |
6 |
Correct |
1 ms |
8536 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
1 ms |
8536 KB |
Output is correct |
10 |
Correct |
2 ms |
16728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
2 ms |
8540 KB |
Output is correct |
4 |
Correct |
3 ms |
16732 KB |
Output is correct |
5 |
Correct |
2 ms |
16732 KB |
Output is correct |
6 |
Correct |
1 ms |
8536 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
1 ms |
8536 KB |
Output is correct |
10 |
Correct |
2 ms |
16728 KB |
Output is correct |
11 |
Execution timed out |
1549 ms |
6740 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
2 ms |
8540 KB |
Output is correct |
4 |
Correct |
3 ms |
16732 KB |
Output is correct |
5 |
Correct |
2 ms |
16732 KB |
Output is correct |
6 |
Correct |
1 ms |
8536 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
1 ms |
8536 KB |
Output is correct |
10 |
Correct |
2 ms |
16728 KB |
Output is correct |
11 |
Execution timed out |
1549 ms |
6740 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |