QOJ.ac
QOJ
QOJ is currently under a maintenance. It might be unavailable in the following a few hours.
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#703862 | #1066. ROBOTS | TheZone | 500 ✓ | 524ms | 88272kb | C++20 | 4.3kb | 2024-11-02 18:44:22 | 2024-11-02 18:44:24 |
Judging History
answer
#include <bits/stdc++.h>
#define FOR(i,j,k) for(int i=j; i<=k; ++i)
#define ROF(i,j,k) for(int i=j; i>=k; --i)
inline int read (void) {
int x = 0, f = 1, ch = getchar();
while(!isdigit(ch)) { if(ch == '-') f = -f; ch = getchar(); }
while(isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); }
return x * f;
}
using pii = std::pair <int, int>;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int maxN = 10;
const int maxn = 505;
const int maxv = 250005;
char c[maxn][maxn];
int d[maxN][maxN][maxv], id[maxn][maxn], t[maxn][maxn][4];
bool ins[maxn][maxn][4];
std::vector <int> v[maxv];
int dfs (int x, int y, int k) {
if(ins[x][y][k]) return t[x][y][k] = -1;
if(t[x][y][k] != -2) return t[x][y][k];
ins[x][y][k] = 1; int X = x + dx[k], Y = y + dy[k];
if(c[X][Y] == 'x') t[x][y][k] = id[x][y];
else if(c[X][Y] == 'A') t[x][y][k] = dfs (X, Y, (k + 3) % 4);
else if(c[X][Y] == 'C') t[x][y][k] = dfs (X, Y, (k + 1) % 4);
else t[x][y][k] = dfs (X, Y, k);
ins[x][y][k] = 0; return t[x][y][k];
}
std::queue <pii> q, Q;
std::vector <pii> vec;
int main (void) {
int N = read(), m = read(), n = read(), o = n * m;
FOR(i,1,n) {
scanf("%s", c[i]+1);
FOR(j,1,m) id[i][j] = (i - 1) * m + j;
}
FOR(i,1,n) c[i][0] = c[i][m+1] = 'x';
FOR(j,1,m) c[0][j] = c[n+1][j] = 'x';
FOR(i,1,n) FOR(j,1,m) if(c[i][j] != 'x') FOR(k,0,3) t[i][j][k] = -2;
FOR(i,1,n) FOR(j,1,m) if(c[i][j] != 'x') FOR(k,0,3) dfs (i, j, k);
FOR(i,1,n) FOR(j,1,m) if(c[i][j] != 'x') FOR(k,0,3) if(t[i][j][k] != -1) v[id[i][j]].push_back (t[i][j][k]);
FOR(l,1,N) FOR(r,l,N) std::fill (d[l][r]+1, d[l][r]+o+1, 1 << 29);
ROF(l,N,1) FOR(r,1,N) {
if(l == r) { FOR(i,1,n) FOR(j,1,m) if(c[i][j] == l + '0') d[l][r][id[i][j]] = 0; }
else FOR(M,l,r-1) FOR(i,1,o) d[l][r][i] = std::min(d[l][r][i], d[l][M][i] + d[M+1][r][i]);
FOR(i,1,o) if(d[l][r][i] != 1 << 29) vec.emplace_back (d[l][r][i], i);
std::sort(vec.begin(), vec.end());
for(auto&it:vec) q.push (it);
vec.clear(); pii cur;
while(!q.empty() || !Q.empty()) {
if(Q.empty() || !q.empty() && q.front().first < Q.front().first)
cur = q.front(), q.pop(); else cur = Q.front(), Q.pop();
if(cur.first > d[l][r][cur.second]) continue;
for(auto&it:v[cur.second]) if(d[l][r][it] > d[l][r][cur.second] + 1)
Q.emplace (d[l][r][it] = d[l][r][cur.second] + 1, it);
}
}
int ans = *std::min_element (d[1][N]+1, d[1][N]+o+1);
printf("%d\n", ans == 1 << 29 ? -1 : ans);
return 0;
}
詳細信息
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 2ms
memory: 12272kb
input:
2 2 1 12
output:
1
result:
ok single line: '1'
Test #2:
score: 10
Accepted
time: 2ms
memory: 11928kb
input:
2 3 1 1x2
output:
-1
result:
ok single line: '-1'
Test #3:
score: 10
Accepted
time: 2ms
memory: 12232kb
input:
2 4 1 .12.
output:
2
result:
ok single line: '2'
Test #4:
score: 10
Accepted
time: 0ms
memory: 14052kb
input:
2 10 10 ...x...x.2 .x.x.x.x.x .x.x.x.x.x .x.x.x.x.x .x.x.x.x.x .x.x.x.x.x .x.x.x.x.x .x.x.x.x.x .x.x.x.x.x 1x...x...x
output:
10
result:
ok single line: '10'
Test #5:
score: 10
Accepted
time: 2ms
memory: 11932kb
input:
2 10 10 .......... .xx..xx... xx..xx..x. x..xx..xx. ..xx..xx.. .xx..xx..x xx..xx..xx x..xx..xx2 ..xx..xx.. 1xx......x
output:
29
result:
ok single line: '29'
Subtask #2:
score: 20
Accepted
Dependency #1:
100%
Accepted
Test #6:
score: 20
Accepted
time: 2ms
memory: 14124kb
input:
2 2 2 1C .2
output:
1
result:
ok single line: '1'
Test #7:
score: 20
Accepted
time: 2ms
memory: 14036kb
input:
2 3 1 1A2
output:
2
result:
ok single line: '2'
Test #8:
score: 20
Accepted
time: 0ms
memory: 14092kb
input:
2 3 3 .x. 1CA .x2
output:
2
result:
ok single line: '2'
Test #9:
score: 20
Accepted
time: 0ms
memory: 11996kb
input:
2 6 2 C1CA2A CCCAAA
output:
6
result:
ok single line: '6'
Test #10:
score: 20
Accepted
time: 2ms
memory: 14076kb
input:
2 10 10 C.CxC.CxC2 .x.x.x.x.x .x.x.x.x.x .x.x.x.x.x .x.x.x.x.x .x.x.x.x.x .x.x.x.x.x .x.x.x.x.x .x.x.x.x.x 1xA.AxA.Ax
output:
1
result:
ok single line: '1'
Subtask #3:
score: 30
Accepted
Dependency #2:
100%
Accepted
Test #11:
score: 30
Accepted
time: 101ms
memory: 70240kb
input:
9 296 298 2..x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...xx...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x....
output:
47593
result:
ok single line: '47593'
Test #12:
score: 30
Accepted
time: 0ms
memory: 17960kb
input:
1 296 298 1..x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...xx...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x....
output:
0
result:
ok single line: '0'
Test #13:
score: 30
Accepted
time: 50ms
memory: 49476kb
input:
7 300 300 .x...x...x...x...x..4x...x...x...x...x...x...x...x..1x...x...x...x...x...x..5x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x..6x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x..7x...x...
output:
438
result:
ok single line: '438'
Test #14:
score: 30
Accepted
time: 183ms
memory: 73508kb
input:
9 296 298 1AAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxC...
output:
45376
result:
ok single line: '45376'
Test #15:
score: 30
Accepted
time: 95ms
memory: 68048kb
input:
9 296 298 4..x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...xx...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x....
output:
-1
result:
ok single line: '-1'
Subtask #4:
score: 40
Accepted
Dependency #3:
100%
Accepted
Test #16:
score: 40
Accepted
time: 274ms
memory: 85836kb
input:
9 500 500 .....................................................................................................................................................................................................................................................................................................
output:
44
result:
ok single line: '44'
Test #17:
score: 40
Accepted
time: 524ms
memory: 87256kb
input:
9 496 500 2AAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxC...
output:
138163
result:
ok single line: '138163'
Test #18:
score: 40
Accepted
time: 264ms
memory: 87200kb
input:
9 496 500 4..x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...xx...x...x...x...x...x...x...x...x...x...x....
output:
-1
result:
ok single line: '-1'
Test #19:
score: 40
Accepted
time: 251ms
memory: 88272kb
input:
9 500 500 .x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x..4x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x..7x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...
output:
484
result:
ok single line: '484'
Test #20:
score: 40
Accepted
time: 391ms
memory: 83224kb
input:
9 496 500 4..x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...xx...x...x...x...x...x...x...x...x...x...x....
output:
126926
result:
ok single line: '126926'