QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#125328 | #6739. Teleport | awellwell | TL | 665ms | 120300kb | C++14 | 1.9kb | 2023-07-16 15:53:14 | 2023-07-16 15:53:15 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define forn(i,p,q) for(long long i = p;i <=q;i++)
long long read()
{
long long t;
cin >> t;
return t;
}
#define all(p) p.begin(),p.end()
const int N = 5005;
#define pii pair<int,int>
set <int> st[2 * N];
int dis[N][N];
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int n, k;
bool ps[N][N];
inline bool check(pii t)
{
int i = t.first, j = t.second;
return i <= n && j <= n && i >= 1 && j >= 1;
}
void BFS()
{
queue <pii> qu;
dis[1][1] = 0;
qu.emplace(1,1);
while(!qu.empty())
{
auto t = qu.front();
qu.pop();
forn(i,0,3)
{
auto pt = pii(t.first + dx[i], t.second + dy[i]);
if(check(pt) && ps[pt.first][pt.second] && dis[pt.first][pt.second] == -1)
{
dis[pt.first][pt.second] = dis[t.first][t.second] + 1;
qu.push(pt);
}
}
forn(i,1,k/2)
{
auto pt = pii(t.first + i, t.second + i);
if(check(pt)&& ps[pt.first][pt.second] && dis[pt.first][pt.second] == -1)
{
dis[pt.first][pt.second] = dis[t.first][t.second] + 1;
if(ps[pt.first][pt.second]) qu.push(pt);
}
}
forn(i,1,(k + 1)/2)
{
auto pt = pii(t.second + i,t.first + i-1);
if(check(pt)&& ps[pt.first][pt.second] && dis[pt.first][pt.second] == -1)
{
dis[pt.first][pt.second] = dis[t.first][t.second] + 1;
qu.push(pt);
}
}
}
}
#define FAST ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
int main()
{
scanf("%d %d\n", &n, &k);
memset(dis,-1,sizeof(dis));
forn(i,1,n)
{
forn(j,1,n)
{
ps[i][j] = getchar() == '.';
}
getchar();
}
BFS();
printf("%d", dis[n][n]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 103564kb
input:
3 2 .*. .*. ...
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 103608kb
input:
3 3 .*. .*. ...
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 38ms
memory: 108052kb
input:
961 4 ...*.*..*.....*.*..*..*..*.*.*.*.....*.....*....*..*...*....*.........*....*....*...*......*..*..*...*..*...*.....*...*...*.*.*.........**..**.......*.......*...*...*.*.*........*....*..*..*...*.....*.*......**.**..**...*..*.**.....*....*.*.*..*..*..*.*..*.*..*......*..*..*.*......*...*.*...*....
output:
540
result:
ok 1 number(s): "540"
Test #4:
score: 0
Accepted
time: 665ms
memory: 110080kb
input:
975 434 .*......*...*....*......*..*...*...**....*....*.......*...*.....*..*..*.*.*..*.*..*..*.*....*.*.*..*...*.*.....*......*.*...*......*..*..*......**..**.......*...*.*..*..*.*.**....*.*.*.....*....**.*..*..**.*..*.....*.*......*..*...*..*...*....**...*....*..*.*.*...........*..*.**.*.*..*.*..**...
output:
5
result:
ok 1 number(s): "5"
Test #5:
score: 0
Accepted
time: 93ms
memory: 110136kb
input:
966 19 ..*.*.*........*.*..*.**..*....*..*..*....*.**..*.*.*..*.*.*..**....*.*.*....*.....*...........*.*..*.....*..*...*....*.*...*.*...*....*...*...*.*.*....*.*....**.*.......*....*.*.*...*..*..*..*.*...*...*...*..*..*..........*.*....*.*......*...*..**....*.*....**.....*..*..*..*.*....*...*..*.*....
output:
104
result:
ok 1 number(s): "104"
Test #6:
score: 0
Accepted
time: 464ms
memory: 108040kb
input:
973 199 ..**.*...*.*...*.*.*.*.**..*.*.*..*......*.....*.*.*..*...**.....*.*..*.*..*...*....*..*...*....*.*...*.*......*..*.*.*.*......**......*.*.*.*.*.*...*...*...*....*......*.*.*.*..*..*..*...*..*.*....*....*.*...*..*..*.*..**.**..*.**....*.*...*..**..**...*......*.....*.....*..*.*.......*.*.*.....
output:
10
result:
ok 1 number(s): "10"
Test #7:
score: 0
Accepted
time: 281ms
memory: 108052kb
input:
984 95 .....*.*...*....*..*....*.*....**.**......*....*.*.*.......*.....*.*..*....*..*....*.*.....*..*.......*.*......*.*....*.....*......*...*....*....*......*....*.*...*........*......*.*....*.*...*....*..**....*.*.*.**....*..*.*..*..*.*......*..*......*.*......*...*......*.......*...*....*...**.....
output:
21
result:
ok 1 number(s): "21"
Test #8:
score: 0
Accepted
time: 271ms
memory: 120300kb
input:
2996 2 ..*..*.....*..*.....*....**..*...........*..*........*..*..*.*..*..*.*.*.**.*.....**.*.......*.......*..*....*.....*..*.*.*....**.....*..**.....*.....*.......*.*.*.*....*...*..*.**......**..*.*...**..*..*......*..*.*...*......*.*.*.*...**.**..*.*........*.*..*...**......*.*..*.*..*....*.*.*.*...
output:
3354
result:
ok 1 number(s): "3354"
Test #9:
score: -100
Time Limit Exceeded
input:
2905 1023 .........*..*.**.....*...*.*....*.*.**.*..*...*..*....*...*.**.*.*.**..*......*...*.**..*...*..*.........*.........*.*.....**.*.*........*.....*.*....*..*.*.....*..*..*..*.*..*....**...*.*..*....*......*.........*.*.*.*......**.**.**..*.*.*..*..**..*..*...*...*.*.......*..*..*....*.*.........