QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#125557#6739. TeleportawellwellAC ✓372ms238076kbC++142.5kb2023-07-16 20:50:172023-07-16 20:50:20

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-16 20:50:20]
  • 评测
  • 测评结果:AC
  • 用时:372ms
  • 内存:238076kb
  • [2023-07-16 20:50:17]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
#define forn(i,p,q) for(long long i = p;i <=q;i++)
long long read()
{
 	long long t;
 	cin >> t;
  	return t;
}
#define all(p) p.begin(),p.end()
const int N = 5005;
#define pii pair<int,int>
#define x first
#define y second
set <int> st[2 * N];
int dis[N][N];
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int n, k;
bool ps[N][N];
int jump[2 * N][N];
inline bool check(int i,int j)
{
	return i <= n && j <= n && i >= 1 && j >= 1;
}
int consttemp;
int & getjump(int p, int q)
{
    if(!check(p,q)) return consttemp;
    return jump[p-q+n][p];
}
void BFS()
{
	queue <pii> qu;
	qu.emplace(1,1);
	dis[1][1] = 0;
	while(!qu.empty())
	{
		auto pt = qu.front(); qu.pop();
        if(!ps[pt.x][pt.y] || !check(pt.x,pt.y)) continue;
        forn(i,0,3)
        {
            pii nw = make_pair(pt.x+dx[i], pt.y + dy[i]);
            if(check(nw.x, nw.y) && dis[nw.x][nw.y] == -1)
            {
                dis[nw.x][nw.y] = dis[pt.x][pt.y] + 1;
                qu.push(nw);
            }
        }
        forn(i,getjump(pt.x, pt.y), pt.x + k/2)
        {
            pii nw = make_pair(i, pt.y + i - pt.x);
            if(!check(nw.x,nw.y)) continue;
            if(check(nw.x, nw.y) && dis[nw.x][nw.y] == -1)
            {
                dis[nw.x][nw.y] = dis[pt.x][pt.y] + 1;
                qu.push(nw);
            }
            getjump(nw.x, nw.y) = getjump(pt.x+k/2, pt.y+k/2);
        }
        forn(i,getjump(pt.y, pt.x-1), pt.y + (k+1)/2)
        {
            pii nw = make_pair(i, pt.x + i - pt.y-1);
            if(!check(nw.x,nw.y)) continue;
            if(check(nw.x, nw.y) && dis[nw.x][nw.y] == -1)
            {
                dis[nw.x][nw.y] = dis[pt.x][pt.y] + 1;
                qu.push(nw);
            }
            getjump(nw.x, nw.y) = getjump(pt.y+(k+1)/2, pt.x+(k+1)/2-1);
        }
        getjump(pt.x, pt.y) = getjump(pt.x+k/2, pt.y+k/2);
        if(dis[n][n] != -1) return ;
	}
}
#define FAST ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
int main()
{
    scanf("%d %d\n", &n, &k);
	memset(dis,-1,sizeof(dis));
    consttemp = n + 1;
	forn(i,1,n)
    {
        forn(j,1,n)
        {
            ps[i][j] = getchar() == '.';
        }
        getchar();
    }
    forn(i,0,2 * n + 2) jump[i][0] = 1;
    for(int i = n;i;i--) for(int j = n;j;j--)
    {
        jump[i-j+n][i] = i + 1;
    }
	BFS();
    printf("%d", dis[n][n]);
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 7ms
memory: 105796kb

input:

3 2
.*.
.*.
...

output:

3

result:

ok 1 number(s): "3"

Test #2:

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

input:

3 3
.*.
.*.
...

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 26ms
memory: 146496kb

input:

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

output:

540

result:

ok 1 number(s): "540"

Test #4:

score: 0
Accepted
time: 14ms
memory: 147300kb

input:

975 434
.*......*...*....*......*..*...*...**....*....*.......*...*.....*..*..*.*.*..*.*..*..*.*....*.*.*..*...*.*.....*......*.*...*......*..*..*......**..**.......*...*.*..*..*.*.**....*.*.*.....*....**.*..*..**.*..*.....*.*......*..*...*..*...*....**...*....*..*.*.*...........*..*.**.*.*..*.*..**...

output:

5

result:

ok 1 number(s): "5"

Test #5:

score: 0
Accepted
time: 14ms
memory: 148848kb

input:

966 19
..*.*.*........*.*..*.**..*....*..*..*....*.**..*.*.*..*.*.*..**....*.*.*....*.....*...........*.*..*.....*..*...*....*.*...*.*...*....*...*...*.*.*....*.*....**.*.......*....*.*.*...*..*..*..*.*...*...*...*..*..*..........*.*....*.*......*...*..**....*.*....**.....*..*..*..*.*....*...*..*.*....

output:

104

result:

ok 1 number(s): "104"

Test #6:

score: 0
Accepted
time: 11ms
memory: 147476kb

input:

973 199
..**.*...*.*...*.*.*.*.**..*.*.*..*......*.....*.*.*..*...**.....*.*..*.*..*...*....*..*...*....*.*...*.*......*..*.*.*.*......**......*.*.*.*.*.*...*...*...*....*......*.*.*.*..*..*..*...*..*.*....*....*.*...*..*..*.*..**.**..*.**....*.*...*..**..**...*......*.....*.....*..*.*.......*.*.*.....

output:

10

result:

ok 1 number(s): "10"

Test #7:

score: 0
Accepted
time: 16ms
memory: 147572kb

input:

984 95
.....*.*...*....*..*....*.*....**.**......*....*.*.*.......*.....*.*..*....*..*....*.*.....*..*.......*.*......*.*....*.....*......*...*....*....*......*....*.*...*........*......*.*....*.*...*....*..**....*.*.*.**....*..*.*..*..*.*......*..*......*.*......*...*......*.......*...*....*...**.....

output:

21

result:

ok 1 number(s): "21"

Test #8:

score: 0
Accepted
time: 372ms
memory: 238076kb

input:

2996 2
..*..*.....*..*.....*....**..*...........*..*........*..*..*.*..*..*.*.*.**.*.....**.*.......*.......*..*....*.....*..*.*.*....**.....*..**.....*.....*.......*.*.*.*....*...*..*.**......**..*.*...**..*..*......*..*.*...*......*.*.*.*...**.**..*.*........*.*..*...**......*.*..*.*..*....*.*.*.*...

output:

3354

result:

ok 1 number(s): "3354"

Test #9:

score: 0
Accepted
time: 84ms
memory: 232788kb

input:

2905 1023
.........*..*.**.....*...*.*....*.*.**.*..*...*..*....*...*.**.*.*.**..*......*...*.**..*...*..*.........*.........*.*.....**.*.*........*.....*.*....*..*.*.....*..*..*..*.*..*....**...*.*..*....*......*.........*.*.*.*......**.**.**..*.*.*..*..**..*..*...*...*.*.......*..*..*....*.*.........

output:

6

result:

ok 1 number(s): "6"

Test #10:

score: 0
Accepted
time: 114ms
memory: 235940kb

input:

2978 104
.*.........*...**.....*...*........*..*...*.*.*.....*........*.*...*.....*...*....*...*..*...*..*..*....*...*..*.*....*....*...*.......*.*.....*.*.......*.*..*...*.*.......*.*.*..........*.*..*.*..**.*....*.*.*..*...*.*.*.....*....*...*.*.*.*.........*.*.....**.*.*..*.*....*........*...*.**...

output:

58

result:

ok 1 number(s): "58"