QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#218618 | #6739. Teleport | Geospiza# | TL | 426ms | 141560kb | C++20 | 2.4kb | 2023-10-18 15:55:11 | 2023-10-18 15:55:11 |
Judging History
answer
#include <bits/stdc++.h>
#define ll int
#define Ma 20210926
#define N 5005
#define mod 998244353
#define PLL pair<ll,ll>
#define x first
#define y second
#define pb push_back
using namespace std;
ll dp[N][N],vis[N][N];
string s[N];
ll n,k;
ll id[N][N];
ll len[N][N];
ll tot=0;
set <ll> st[N];
vector <PLL> v[N];
ll px[4]={1,-1,0,0},py[4]={0,0,1,-1};
void sol()
{
cin>>n>>k;
for (ll l=0;l<=n*2-2;l++)
{
for (ll i=0;i<n;i++)
{
ll j=l-i;
if (j<0||j>=n)
continue;
if (id[i][j]==0)
{
id[i][j]=++tot;
len[i][j]=0;
st[tot].insert(len[i][j]);
v[tot].pb({i,j});
}
if (j+1<n)
{
id[j+1][i]=id[i][j];
len[j+1][i]=len[i][j]+1;
st[id[j+1][i]].insert(len[j+1][i]);
v[id[j+1][i]].pb({j+1,i});
}
}
}
for (ll i=0;i<n;i++)
cin>>s[i];
for (ll i=0;i<n;i++)
for (ll j=0;j<n;j++)
if (s[i][j]=='*')
st[id[i][j]].erase(len[i][j]);
queue <PLL> q;
q.push({0,0});
st[id[0][0]].erase(0);
vis[0][0]=1;
while (!q.empty())
{
PLL p=q.front();
//printf("x=%d y=%d dp=%d\n",p.x,p.y,dp[p.x][p.y]);
q.pop();
for (ll i=0;i<4;i++){
ll nx=p.x+px[i],ny=p.y+py[i];
if (nx<0||nx>=n||ny<0||ny>=n||vis[nx][ny]||s[nx][ny]=='*')
continue;
vis[nx][ny]=1,dp[nx][ny]=dp[p.x][p.y]+1;
q.push({nx,ny});
st[id[nx][ny]].erase(len[nx][ny]);
}
vector <ll> er;
auto l=st[id[p.x][p.y]].lower_bound(len[p.x][p.y]);
//printf("l=%d\n",(*l));
while (l!=st[id[p.x][p.y]].end()&&(*l)<=len[p.x][p.y]+k)
er.pb((*l)),l++;
for (auto z:er)
{
PLL ok=v[id[p.x][p.y]][z];
dp[ok.x][ok.y]=dp[p.x][p.y]+1;
vis[ok.x][ok.y]=1;
st[id[p.x][p.y]].erase(z);
q.push(ok);
}
}
if (!vis[n-1][n-1])
{
printf("-1\n");
return;
}
printf("%d\n",dp[n-1][n-1]);
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0);
ll tt=1;
//cin>>tt;
while (tt--)
sol();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 8304kb
input:
3 2 .*. .*. ...
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 6164kb
input:
3 3 .*. .*. ...
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 389ms
memory: 136596kb
input:
961 4 ...*.*..*.....*.*..*..*..*.*.*.*.....*.....*....*..*...*....*.........*....*....*...*......*..*..*...*..*...*.....*...*...*.*.*.........**..**.......*.......*...*...*.*.*........*....*..*..*...*.....*.*......**.**..**...*..*.**.....*....*.*.*..*..*..*.*..*.*..*......*..*..*.*......*...*.*...*....
output:
540
result:
ok 1 number(s): "540"
Test #4:
score: 0
Accepted
time: 418ms
memory: 140860kb
input:
975 434 .*......*...*....*......*..*...*...**....*....*.......*...*.....*..*..*.*.*..*.*..*..*.*....*.*.*..*...*.*.....*......*.*...*......*..*..*......**..**.......*...*.*..*..*.*.**....*.*.*.....*....**.*..*..**.*..*.....*.*......*..*...*..*...*....**...*....*..*.*.*...........*..*.**.*.*..*.*..**...
output:
5
result:
ok 1 number(s): "5"
Test #5:
score: 0
Accepted
time: 404ms
memory: 135660kb
input:
966 19 ..*.*.*........*.*..*.**..*....*..*..*....*.**..*.*.*..*.*.*..**....*.*.*....*.....*...........*.*..*.....*..*...*....*.*...*.*...*....*...*...*.*.*....*.*....**.*.......*....*.*.*...*..*..*..*.*...*...*...*..*..*..........*.*....*.*......*...*..**....*.*....**.....*..*..*..*.*....*...*..*.*....
output:
104
result:
ok 1 number(s): "104"
Test #6:
score: 0
Accepted
time: 426ms
memory: 138688kb
input:
973 199 ..**.*...*.*...*.*.*.*.**..*.*.*..*......*.....*.*.*..*...**.....*.*..*.*..*...*....*..*...*....*.*...*.*......*..*.*.*.*......**......*.*.*.*.*.*...*...*...*....*......*.*.*.*..*..*..*...*..*.*....*....*.*...*..*..*.*..**.**..*.**....*.*...*..**..**...*......*.....*.....*..*.*.......*.*.*.....
output:
10
result:
ok 1 number(s): "10"
Test #7:
score: 0
Accepted
time: 419ms
memory: 141560kb
input:
984 95 .....*.*...*....*..*....*.*....**.**......*....*.*.*.......*.....*.*..*....*..*....*.*.....*..*.......*.*......*.*....*.....*......*...*....*....*......*....*.*...*........*......*.*....*.*...*....*..**....*.*.*.**....*..*.*..*..*.*......*..*......*.*......*...*......*.......*...*....*...**.....
output:
21
result:
ok 1 number(s): "21"
Test #8:
score: -100
Time Limit Exceeded
input:
2996 2 ..*..*.....*..*.....*....**..*...........*..*........*..*..*.*..*..*.*.*.**.*.....**.*.......*.......*..*....*.....*..*.*.*....**.....*..**.....*.....*.......*.*.*.*....*...*..*.**......**..*.*...**..*..*......*..*.*...*......*.*.*.*...**.**..*.*........*.*..*...**......*.*..*.*..*....*.*.*.*...