QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#177729 | #6739. Teleport | ucup-team870 | AC ✓ | 320ms | 218568kb | C++17 | 1.6kb | 2023-09-13 11:39:29 | 2023-09-13 11:39:30 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
#define rep(i,j,k) for(int i=j;i<=k;++i)
#define Rep(i,j,k) for(int i=j;i<k;++i)
#define per(i,j,k) for(int i=j;i>=k;--i)
#define P pair<int,int>
#define ll long long
#define vi vector<int>
const int N=5005;
const P dir[4]={{-1,0},{1,0},{0,1},{0,-1}};
int n,k;
int fa[N*2][N],dis[N][N];
P q[N*N]; int L=1,R=0;
char s[N][N];
bool ok(int x,int y){
return 1<=x && x<=n && 1<=y && y<=n;
}
int fd(int fa[],int x){
if(!fa[x])return x;
return fa[x]=fd(fa,fa[x]);
}
void line(int x,int y,int cnt,int val){
// cout<<x<<' '<<y<<' '<<cnt<<'h'<<'\n';
int ux=x+cnt;
while(x<ux && ok(x,y)){
int d=x-y+N,nx=fd(fa[d],x);
y+=nx-x; x=nx;
if(x>=ux || !ok(x,y))break;
if(dis[x][y]==-1 && s[x][y]=='.')dis[x][y]=val,q[++R]={x,y};
fa[d][x]=x+1;
++x,++y;
}
}
signed main(){
IOS
cin>>n>>k;
rep(i,1,n)cin>>s[i]+1;
// rep(i,1,n){
// rep(j,1,n)fa[i-j+N][i]=i;
// }
memset(dis,-1,sizeof dis); dis[1][1]=0;
q[++R]={1,1};
while(L<=R){
auto [x,y]=q[L++]; int nd=dis[x][y]+1;
// cout<<x<<' '<<y<<'\n';
if(x==n && y==n){
cout<<dis[x][y];return 0;
}
rep(i,0,3){
int xx=x+dir[i].first,yy=y+dir[i].second;
if(!ok(xx,yy) || dis[xx][yy]!=-1 || s[xx][yy]!='.')continue;
dis[xx][yy]=nd; q[++R]={xx,yy};
}
line(x+1,y+1,k/2,nd);
line(y+1,x,(k+1)/2,nd);
}
cout<<-1;
}
/*
3 2
.*.
.*.
...
*/
詳細信息
Test #1:
score: 100
Accepted
time: 8ms
memory: 102168kb
input:
3 2 .*. .*. ...
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 4ms
memory: 101624kb
input:
3 3 .*. .*. ...
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 28ms
memory: 116876kb
input:
961 4 ...*.*..*.....*.*..*..*..*.*.*.*.....*.....*....*..*...*....*.........*....*....*...*......*..*..*...*..*...*.....*...*...*.*.*.........**..**.......*.......*...*...*.*.*........*....*..*..*...*.....*.*......**.**..**...*..*.**.....*....*.*.*..*..*..*.*..*.*..*......*..*..*.*......*...*.*...*....
output:
540
result:
ok 1 number(s): "540"
Test #4:
score: 0
Accepted
time: 0ms
memory: 108676kb
input:
975 434 .*......*...*....*......*..*...*...**....*....*.......*...*.....*..*..*.*.*..*.*..*..*.*....*.*.*..*...*.*.....*......*.*...*......*..*..*......**..**.......*...*.*..*..*.*.**....*.*.*.....*....**.*..*..**.*..*.....*.*......*..*...*..*...*....**...*....*..*.*.*...........*..*.**.*.*..*.*..**...
output:
5
result:
ok 1 number(s): "5"
Test #5:
score: 0
Accepted
time: 11ms
memory: 110164kb
input:
966 19 ..*.*.*........*.*..*.**..*....*..*..*....*.**..*.*.*..*.*.*..**....*.*.*....*.....*...........*.*..*.....*..*...*....*.*...*.*...*....*...*...*.*.*....*.*....**.*.......*....*.*.*...*..*..*..*.*...*...*...*..*..*..........*.*....*.*......*...*..**....*.*....**.....*..*..*..*.*....*...*..*.*....
output:
104
result:
ok 1 number(s): "104"
Test #6:
score: 0
Accepted
time: 8ms
memory: 108820kb
input:
973 199 ..**.*...*.*...*.*.*.*.**..*.*.*..*......*.....*.*.*..*...**.....*.*..*.*..*...*....*..*...*....*.*...*.*......*..*.*.*.*......**......*.*.*.*.*.*...*...*...*....*......*.*.*.*..*..*..*...*..*.*....*....*.*...*..*..*.*..**.**..*.**....*.*...*..**..**...*......*.....*.....*..*.*.......*.*.*.....
output:
10
result:
ok 1 number(s): "10"
Test #7:
score: 0
Accepted
time: 3ms
memory: 108828kb
input:
984 95 .....*.*...*....*..*....*.*....**.**......*....*.*.*.......*.....*.*..*....*..*....*.*.....*..*.......*.*......*.*....*.....*......*...*....*....*......*....*.*...*........*......*.*....*.*...*....*..**....*.*.*.**....*..*.*..*..*.*......*..*......*.*......*...*......*.......*...*....*...**.....
output:
21
result:
ok 1 number(s): "21"
Test #8:
score: 0
Accepted
time: 320ms
memory: 218568kb
input:
2996 2 ..*..*.....*..*.....*....**..*...........*..*........*..*..*.*..*..*.*.*.**.*.....**.*.......*.......*..*....*.....*..*.*.*....**.....*..**.....*.....*.......*.*.*.*....*...*..*.**......**..*.*...**..*..*......*..*.*...*......*.*.*.*...**.**..*.*........*.*..*...**......*.*..*.*..*....*.*.*.*...
output:
3354
result:
ok 1 number(s): "3354"
Test #9:
score: 0
Accepted
time: 0ms
memory: 118996kb
input:
2905 1023 .........*..*.**.....*...*.*....*.*.**.*..*...*..*....*...*.**.*.*.**..*......*...*.**..*...*..*.........*.........*.*.....**.*.*........*.....*.*....*..*.*.....*..*..*..*.*..*....**...*.*..*....*......*.........*.*.*.*......**.**.**..*.*.*..*..**..*..*...*...*.*.......*..*..*....*.*.........
output:
6
result:
ok 1 number(s): "6"
Test #10:
score: 0
Accepted
time: 20ms
memory: 118824kb
input:
2978 104 .*.........*...**.....*...*........*..*...*.*.*.....*........*.*...*.....*...*....*...*..*...*..*..*....*...*..*.*....*....*...*.......*.*.....*.*.......*.*..*...*.*.......*.*.*..........*.*..*.*..**.*....*.*.*..*...*.*.*.....*....*...*.*.*.*.........*.*.....**.*.*..*.*....*........*...*.**...
output:
58
result:
ok 1 number(s): "58"