QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#227931 | #6739. Teleport | lsj2009 | WA | 70ms | 145208kb | C++14 | 2.1kb | 2023-10-28 09:33:44 | 2023-10-28 09:33:45 |
Judging History
answer
#include<bits/stdc++.h>
//#define int long long
#define ll long long
#define ull unsigned long long
#define ld long double
#define PII pair<int,int>
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define chkmax(a,b) a=max(a,b)
#define chkmin(a,b) a=min(a,b)
#define rep(k,l,r) for(int k=l;k<=r;++k)
#define per(k,r,l) for(int k=r;k>=l;--k)
#define cl(f,x) memset(f,x,sizeof(f))
using namespace std;
const int dx[]={-1,0,0,1};
const int dy[]={0,-1,1,0};
const int N=5e3+5;
PII fa[N][N];
PII find(int x,int y) {
PII tmp=fa[x][y];
if(tmp.first!=x||tmp.second!=y)
fa[x][y]=find(tmp.first,tmp.second);
return fa[x][y];
}
char mp[N][N];
int n,k;
bool inrange(int x,int y) {
return x>=1&&x<=n&&y>=1&&y<=n;
}
int f[N][N];
queue<PII> q;
void update(int x,int y,int sx,int sy,int val,int k) {
if(!inrange(x,y)||(x-sx)+(y-sy)>k)
return;
if(mp[x][y]=='*') {
update(x+1,y+1,sx,sy,val,k);
return;
}
PII tmp=find(x,y);
int tx=tmp.first,ty=tmp.second;
if(inrange(tx+1,ty+1)&&(tx+1-sx)+(ty+1-sy)<=k) {
if(mp[tx+1][ty+1]=='.') {
fa[tx][ty]={tx+1,ty+1};
if(f[tx+1][ty+1]==-1) {
f[tx+1][ty+1]=val+1;
q.push({tx+1,ty+1});
}
}
update(tx+1,ty+1,sx,sy,val,k);
}
}
void bfs() {
cl(f,-1); f[1][1]=0;
q.push({1,1});
while(!q.empty()) {
PII tmp=q.front(); q.pop();
int x=tmp.first,y=tmp.second;
if(x==n&&y==n) {
printf("%d\n",f[x][y]);
return;
}
rep(i,0,3) {
int tx=x+dx[i],ty=y+dy[i];
if(inrange(tx,ty)&&mp[tx][ty]=='.'&&f[tx][ty]==-1) {
f[tx][ty]=f[x][y]+1;
q.push({tx,ty});
}
}
update(x,y,x,y,f[x][y],k);
update(y+1,x,y+1,x,f[x][y],k-1);
}
puts("-1");
}
signed main() {
scanf("%d%d",&n,&k);
rep(i,1,n) {
rep(j,1,n) {
cin>>mp[i][j];
fa[i][j]={i,j};
}
}
bfs();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 104040kb
input:
3 2 .*. .*. ...
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 104680kb
input:
3 3 .*. .*. ...
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Wrong Answer
time: 70ms
memory: 145208kb
input:
961 4 ...*.*..*.....*.*..*..*..*.*.*.*.....*.....*....*..*...*....*.........*....*....*...*......*..*..*...*..*...*.....*...*...*.*.*.........**..**.......*.......*...*...*.*.*........*....*..*..*...*.....*.*......**.**..**...*..*.**.....*....*.*.*..*..*..*.*..*.*..*......*..*..*.*......*...*.*...*....
output:
638
result:
wrong answer 1st numbers differ - expected: '540', found: '638'