QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#227932#6739. Teleportlsj2009WA 52ms145776kbC++142.1kb2023-10-28 09:39:102023-10-28 09:39:10

Judging History

你现在查看的是最新测评结果

  • [2023-10-28 09:39:10]
  • 评测
  • 测评结果:WA
  • 用时:52ms
  • 内存:145776kb
  • [2023-10-28 09:39:10]
  • 提交

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(mp[x][y]=='*') {
		if((x+1-sx)+(y+1-sy)<=k&&inrange(x+1,y+1)) {
			fa[x][y]={x+1,y+1};
			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]=='.'&&f[tx+1][ty+1]==-1) {
            f[tx+1][ty+1]=val+1;
            q.push({tx+1,ty+1});
        }
		fa[tx][ty]={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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 105160kb

input:

3 2
.*.
.*.
...

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 0ms
memory: 104992kb

input:

3 3
.*.
.*.
...

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Wrong Answer
time: 52ms
memory: 145776kb

input:

961 4
...*.*..*.....*.*..*..*..*.*.*.*.....*.....*....*..*...*....*.........*....*....*...*......*..*..*...*..*...*.....*...*...*.*.*.........**..**.......*.......*...*...*.*.*........*....*..*..*...*.....*.*......**.**..**...*..*.**.....*....*.*.*..*..*..*.*..*.*..*......*..*..*.*......*...*.*...*....

output:

562

result:

wrong answer 1st numbers differ - expected: '540', found: '562'