QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#177201 | #6739. Teleport | ucup-team870# | AC ✓ | 430ms | 39088kb | C++17 | 2.2kb | 2023-09-12 17:39:26 | 2023-09-12 17:39:27 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l; i<=r; i++)
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
char s[5050][5050];
vector<int> q[10010];
bool vis[5050][5050];
int n, top, visdig[10010];
P ksj[25000010];
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int digs[10010], numdigs;
void mark(int x, int y, int k) {
rep (i, 0, k-1) {
int tx = x + i, ty = y + i;
if (tx > n || ty > n) break;
if (s[tx][ty] == '*') continue;
if (vis[tx][ty]) break;
vis[tx][ty] = 1;
ksj[++top] = P(tx, ty);
}
}
bool cmp(int a, int b) {
return a > b;
}
int main() {
int k;
scanf("%d%d", &n, &k);
rep (i, 1, n) {
scanf("%s", s[i]+1);
}
q[2].push_back(1);
vis[1][1] = 1;
digs[++numdigs] = 2;
visdig[2] = 1;
rep (d, 1, n*n) {
rep (_, 1, numdigs) {
int dig = digs[_];
for (int i = 0; i < q[dig].size(); i++) {
int x = q[dig][i], y = dig - x;
mark(x+1, y+1, k/2);
mark(y+1, x, (k+1)/2);
}
}
rep (_, 1, numdigs) {
int dig = digs[_];
for (int i = 0; i < q[dig].size(); i++) {
int x = q[dig][i], y = dig - x;
rep (l, 0, 3) {
int tx = x + dx[l], ty = y + dy[l];
if (tx >= 1 && tx <= n && ty >= 1 && ty <= n && s[tx][ty] == '.' && !vis[tx][ty]) {
vis[tx][ty] = 1;
ksj[++top] = P(tx, ty);
}
}
}
}
rep (i, 1, numdigs) {
q[digs[i]].clear();
visdig[digs[i]] = 0;
}
numdigs = 0;
rep (i, 1, top) {
int x = ksj[i].first, y = ksj[i].second;
q[x+y].push_back(x);
if (!visdig[x+y]) visdig[x+y] = 1, digs[++numdigs] = x+y;
}
sort(digs+1, digs+numdigs+1, cmp);
top = 0;
if (vis[n][n]) {
cout << d;
return 0;
}
if (numdigs == 0) break;
}
cout <<-1;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7760kb
input:
3 2 .*. .*. ...
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 1ms
memory: 10004kb
input:
3 3 .*. .*. ...
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 25ms
memory: 18008kb
input:
961 4 ...*.*..*.....*.*..*..*..*.*.*.*.....*.....*....*..*...*....*.........*....*....*...*......*..*..*...*..*...*.....*...*...*.*.*.........**..**.......*.......*...*...*.*.*........*....*..*..*...*.....*.*......**.**..**...*..*.**.....*....*.*.*..*..*..*.*..*.*..*......*..*..*.*......*...*.*...*....
output:
540
result:
ok 1 number(s): "540"
Test #4:
score: 0
Accepted
time: 0ms
memory: 15784kb
input:
975 434 .*......*...*....*......*..*...*...**....*....*.......*...*.....*..*..*.*.*..*.*..*..*.*....*.*.*..*...*.*.....*......*.*...*......*..*..*......**..**.......*...*.*..*..*.*.**....*.*.*.....*....**.*..*..**.*..*.....*.*......*..*...*..*...*....**...*....*..*.*.*...........*..*.**.*.*..*.*..**...
output:
5
result:
ok 1 number(s): "5"
Test #5:
score: 0
Accepted
time: 10ms
memory: 14448kb
input:
966 19 ..*.*.*........*.*..*.**..*....*..*..*....*.**..*.*.*..*.*.*..**....*.*.*....*.....*...........*.*..*.....*..*...*....*.*...*.*...*....*...*...*.*.*....*.*....**.*.......*....*.*.*...*..*..*..*.*...*...*...*..*..*..........*.*....*.*......*...*..**....*.*....**.....*..*..*..*.*....*...*..*.*....
output:
104
result:
ok 1 number(s): "104"
Test #6:
score: 0
Accepted
time: 6ms
memory: 17684kb
input:
973 199 ..**.*...*.*...*.*.*.*.**..*.*.*..*......*.....*.*.*..*...**.....*.*..*.*..*...*....*..*...*....*.*...*.*......*..*.*.*.*......**......*.*.*.*.*.*...*...*...*....*......*.*.*.*..*..*..*...*..*.*....*....*.*...*..*..*.*..**.**..*.**....*.*...*..**..**...*......*.....*.....*..*.*.......*.*.*.....
output:
10
result:
ok 1 number(s): "10"
Test #7:
score: 0
Accepted
time: 0ms
memory: 17592kb
input:
984 95 .....*.*...*....*..*....*.*....**.**......*....*.*.*.......*.....*.*..*....*..*....*.*.....*..*.......*.*......*.*....*.....*......*...*....*....*......*....*.*...*........*......*.*....*.*...*....*..**....*.*.*.**....*..*.*..*..*.*......*..*......*.*......*...*......*.......*...*....*...**.....
output:
21
result:
ok 1 number(s): "21"
Test #8:
score: 0
Accepted
time: 430ms
memory: 39088kb
input:
2996 2 ..*..*.....*..*.....*....**..*...........*..*........*..*..*.*..*..*.*.*.**.*.....**.*.......*.......*..*....*.....*..*.*.*....**.....*..**.....*.....*.......*.*.*.*....*...*..*.**......**..*.*...**..*..*......*..*.*...*......*.*.*.*...**.**..*.*........*.*..*...**......*.*..*.*..*....*.*.*.*...
output:
3354
result:
ok 1 number(s): "3354"
Test #9:
score: 0
Accepted
time: 14ms
memory: 33132kb
input:
2905 1023 .........*..*.**.....*...*.*....*.*.**.*..*...*..*....*...*.**.*.*.**..*......*...*.**..*...*..*.........*.........*.*.....**.*.*........*.....*.*....*..*.*.....*..*..*..*.*..*....**...*.*..*....*......*.........*.*.*.*......**.**.**..*.*.*..*..**..*..*...*...*.*.......*..*..*....*.*.........
output:
6
result:
ok 1 number(s): "6"
Test #10:
score: 0
Accepted
time: 21ms
memory: 34448kb
input:
2978 104 .*.........*...**.....*...*........*..*...*.*.*.....*........*.*...*.....*...*....*...*..*...*..*..*....*...*..*.*....*....*...*.......*.*.....*.*.......*.*..*...*.*.......*.*.*..........*.*..*.*..**.*....*.*.*..*...*.*.*.....*....*...*.*.*.*.........*.*.....**.*.*..*.*....*........*...*.**...
output:
58
result:
ok 1 number(s): "58"