QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#252301#6739. Teleportucup-team191#TL 4ms104656kbC++142.0kb2023-11-15 17:51:572023-11-15 17:51:59

Judging History

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

  • [2023-11-15 17:51:59]
  • 评测
  • 测评结果:TL
  • 用时:4ms
  • 内存:104656kb
  • [2023-11-15 17:51:57]
  • 提交

answer

#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using vl=vector<ll>;
#define pb push_back
#define all(a) begin(a),end(a)

const int N=5010,MOD=1e9+7;
const char en='\n';
const ll LLINF=1ll<<60;

int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int n,k;
string h[N];
bool bio1[N][N],bio2[N][N];
int dis[N][N];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	memset(dis,63,sizeof(dis));
	cin>>n>>k;
	for (int i=0;i<n;++i) cin>>h[i];
	queue<pii> q;
	q.push({0,0});
	dis[0][0]=0;
	bio1[0][0]=bio2[0][0];
	while (q.size())
	{
		int i=q.front().x,j=q.front().y,d=dis[i][j];
		//cout<<i<<' '<<j<<' '<<d<<en;
		//bio1[i][j]=bio2[i][j]=1;
		q.pop();
		if (i==n-1 && j==n-1)
		{
			cout<<d<<en;
			exit(0);
		}
		int u;
		for (u=1;u<=k/2;++u)
		{
			int i1=i+u,j1=j+u;
			if (i1<0 || j1<0 || i1>=n || j1>=n) break;
			if (bio1[i1][j1]) continue;
			if (dis[i1][j1]<=dis[i][j]) break;
			if (h[i1][j1]=='*') continue;
		}
		for (--u;u>0;--u)
		{
			int i1=i+u,j1=j+u;
			if (i1<0 || j1<0 || i1>=n || j1>=n) break;
			if (bio1[i1][j1]) continue;
			if (h[i1][j1]=='*') continue;
			bio2[i1][j1]=1;
			dis[i1][j1]=d+1;
			q.push({i1,j1});
		}
		for (u=0;u<=(k-1)/2;++u)
		{
			int i1=j+u+1,j1=i+u;
			if (i1<0 || j1<0 || i1>=n || j1>=n) break;
			if (bio1[i1][j1]) continue;
			if (dis[i1][j1]<=dis[i][j]) break;
			if (h[i1][j1]=='*') continue;
		}
		for (--u;u>=0;--u)
		{
			int i1=j+u+1,j1=i+u;
			if (i1<0 || j1<0 || i1>=n || j1>=n) break;
			if (bio1[i1][j1]) continue;
			if (h[i1][j1]=='*') continue;
			bio2[i1][j1]=1;
			dis[i1][j1]=d+1;
			q.push({i1,j1});
		}
		for (int u=0;u<4;++u)
		{
			int i1=i+dx[u],j1=j+dy[u];
			if (i1<0 || j1<0 || i1>=n || j1>=n) continue;
			if (bio1[i1][j1]) continue;
			if (bio2[i1][j1]) continue;
			if (h[i1][j1]=='*') continue;
			bio1[i1][j1]=1;
			dis[i1][j1]=d+1;
			q.push({i1,j1});
		}
	}
	cout<<-1<<en;
}

详细

Test #1:

score: 100
Accepted
time: 4ms
memory: 104656kb

input:

3 2
.*.
.*.
...

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 3ms
memory: 104320kb

input:

3 3
.*.
.*.
...

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Time Limit Exceeded

input:

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

output:


result: