QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#252397 | #6739. Teleport | ucup-team191# | AC ✓ | 448ms | 172968kb | C++14 | 2.0kb | 2023-11-15 19:09:27 | 2023-11-15 19:09:27 |
Judging History
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 bio[N][N];
int nex[N][N],dis[N][N];
const bool DEB=1;
pii getNex(int i,int j)
{
int c=i,dif=j-i;
while (c<n && c+dif<n && nex[c][c+dif]!=c) c=nex[c][c+dif];
while (i<n && i+dif<n && nex[i][i+dif]!=i)
{
int v=nex[i][i+dif];
nex[i][i+dif]=c;
i=v;
}
return {i,i+dif};
}
void rem(int i,int j)
{
bio[i][j]=1;
nex[i][j]=getNex(i+1,j+1).x;
}
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];
for (int i=0;i<n;++i) for (int j=0;j<n;++j) nex[i][j]=i;
queue<pii> q;
q.push({0,0});
dis[0][0]=0;
rem(0,0);
for (int i=n-1;i>=0;--i) for (int j=0;j<n;++j) if (h[i][j]=='*') rem(i,j);
while (q.size())
{
int i=q.front().x,j=q.front().y,d=dis[i][j];
//cout<<i<<' '<<j<<' '<<d<<endl;
//bio1[i][j]=bio2[i][j]=1;
q.pop();
if (i==n-1 && j==n-1)
{
cout<<d<<en;
exit(0);
}
while (1)
{
pii r=getNex(i,j);
int i1=r.x,j1=r.y;
//cout<<i<<' '<<j<<' '<<i1<<' '<<j1<<endl;
if (i1<0 || j1<0 || i1>=n || j1>=n) break;
if (i1-i>k/2) break;
dis[i1][j1]=d+1;
rem(i1,j1);
q.push({i1,j1});
}
while (1)
{
pii r=getNex(j+1,i);
int i1=r.x,j1=r.y;
if (i1<0 || j1<0 || i1>=n || j1>=n) break;
if (j1-i>(k-1)/2) break;
dis[i1][j1]=d+1;
rem(i1,j1);
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 (bio[i1][j1]) continue;
if (h[i1][j1]=='*') continue;
dis[i1][j1]=d+1;
rem(i1,j1);
q.push({i1,j1});
}
}
cout<<-1<<en;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 101600kb
input:
3 2 .*. .*. ...
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 101704kb
input:
3 3 .*. .*. ...
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 32ms
memory: 114736kb
input:
961 4 ...*.*..*.....*.*..*..*..*.*.*.*.....*.....*....*..*...*....*.........*....*....*...*......*..*..*...*..*...*.....*...*...*.*.*.........**..**.......*.......*...*...*.*.*........*....*..*..*...*.....*.*......**.**..**...*..*.**.....*....*.*.*..*..*..*.*..*.*..*......*..*..*.*......*...*.*...*....
output:
540
result:
ok 1 number(s): "540"
Test #4:
score: 0
Accepted
time: 11ms
memory: 115048kb
input:
975 434 .*......*...*....*......*..*...*...**....*....*.......*...*.....*..*..*.*.*..*.*..*..*.*....*.*.*..*...*.*.....*......*.*...*......*..*..*......**..**.......*...*.*..*..*.*.**....*.*.*.....*....**.*..*..**.*..*.....*.*......*..*...*..*...*....**...*....*..*.*.*...........*..*.**.*.*..*.*..**...
output:
5
result:
ok 1 number(s): "5"
Test #5:
score: 0
Accepted
time: 7ms
memory: 114776kb
input:
966 19 ..*.*.*........*.*..*.**..*....*..*..*....*.**..*.*.*..*.*.*..**....*.*.*....*.....*...........*.*..*.....*..*...*....*.*...*.*...*....*...*...*.*.*....*.*....**.*.......*....*.*.*...*..*..*..*.*...*...*...*..*..*..........*.*....*.*......*...*..**....*.*....**.....*..*..*..*.*....*...*..*.*....
output:
104
result:
ok 1 number(s): "104"
Test #6:
score: 0
Accepted
time: 7ms
memory: 114924kb
input:
973 199 ..**.*...*.*...*.*.*.*.**..*.*.*..*......*.....*.*.*..*...**.....*.*..*.*..*...*....*..*...*....*.*...*.*......*..*.*.*.*......**......*.*.*.*.*.*...*...*...*....*......*.*.*.*..*..*..*...*..*.*....*....*.*...*..*..*.*..**.**..*.**....*.*...*..**..**...*......*.....*.....*..*.*.......*.*.*.....
output:
10
result:
ok 1 number(s): "10"
Test #7:
score: 0
Accepted
time: 8ms
memory: 115136kb
input:
984 95 .....*.*...*....*..*....*.*....**.**......*....*.*.*.......*.....*.*..*....*..*....*.*.....*..*.......*.*......*.*....*.....*......*...*....*....*......*....*.*...*........*......*.*....*.*...*....*..**....*.*.*.**....*..*.*..*..*.*......*..*......*.*......*...*......*.......*...*....*...**.....
output:
21
result:
ok 1 number(s): "21"
Test #8:
score: 0
Accepted
time: 448ms
memory: 172968kb
input:
2996 2 ..*..*.....*..*.....*....**..*...........*..*........*..*..*.*..*..*.*.*.**.*.....**.*.......*.......*..*....*.....*..*.*.*....**.....*..**.....*.....*.......*.*.*.*....*...*..*.**......**..*.*...**..*..*......*..*.*...*......*.*.*.*...**.**..*.*........*.*..*...**......*.*..*.*..*....*.*.*.*...
output:
3354
result:
ok 1 number(s): "3354"
Test #9:
score: 0
Accepted
time: 74ms
memory: 169472kb
input:
2905 1023 .........*..*.**.....*...*.*....*.*.**.*..*...*..*....*...*.**.*.*.**..*......*...*.**..*...*..*.........*.........*.*.....**.*.*........*.....*.*....*..*.*.....*..*..*..*.*..*....**...*.*..*....*......*.........*.*.*.*......**.**.**..*.*.*..*..**..*..*...*...*.*.......*..*..*....*.*.........
output:
6
result:
ok 1 number(s): "6"
Test #10:
score: 0
Accepted
time: 76ms
memory: 172260kb
input:
2978 104 .*.........*...**.....*...*........*..*...*.*.*.....*........*.*...*.....*...*....*...*..*...*..*..*....*...*..*.*....*....*...*.......*.*.....*.*.......*.*..*...*.*.......*.*.*..........*.*..*.*..**.*....*.*.*..*...*.*.*.....*....*...*.*.*.*.........*.*.....**.*.*..*.*....*........*...*.**...
output:
58
result:
ok 1 number(s): "58"