QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#125391 | #6739. Teleport | awellwell | TL | 169ms | 137060kb | C++14 | 2.2kb | 2023-07-16 16:46:07 | 2023-07-16 16:46:09 |
Judging History
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>
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];
inline bool check(int i,int j)
{
return i <= n && j <= n && i >= 1 && j >= 1;
}
inline void ers(int i, int j)
{
st[i-j+n].erase(i);
}
void BFS()
{
queue <pii> qu;
qu.emplace(1,1);
ers(1,1);
dis[1][1] = 0;
while(!qu.empty())
{
auto pt = qu.front();
qu.pop();
pii t;
for(auto&& it = st[pt.first-pt.second + n].lower_bound(pt.first);it != st[pt.first-pt.second + n].end() && *it - pt.first <= k / 2;)
{
t.first = *it;
t.second = t.first - pt.first + pt.second;
++it;
dis[t.first][t.second] = dis[pt.first][pt.second] + 1;
qu.emplace(t.first,t.second);
ers(t.first,t.second);
}
for(auto && it = st[pt.second + 1 - pt.first + n].lower_bound(pt.second + 1);it != st[pt.second + 1 - pt.first + n].end() && *it - pt.second <= (k + 1) / 2;)
{
t.first = *it;
t.second = t.first - pt.second + pt.first - 1;
++it;
dis[t.first][t.second] = dis[pt.first][pt.second] + 1;
qu.emplace(t.first,t.second);
ers(t.first,t.second);
}
forn(i,0,3)
{
t.first = pt.first + dx[i];
t.second = pt.second + dy[i];
if(check(t.first, t.second) && dis[t.first][t.second] == -1 && ps[t.first][t.second])
{
dis[t.first][t.second] = dis[pt.first][pt.second] + 1;
qu.emplace(t.first,t.second);
ers(t.first,t.second);
}
}
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));
forn(i,1,n)
{
forn(j,1,n)
{
ps[i][j] = getchar() == '.';
}
getchar();
}
forn(i,1,n)
{
forn(j,1,n)
{
if(ps[i][j]) st[i-j+n].emplace(i);
}
}
BFS();
printf("%d", dis[n][n]);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 102764kb
input:
3 2 .*. .*. ...
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 8ms
memory: 102304kb
input:
3 3 .*. .*. ...
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 169ms
memory: 134352kb
input:
961 4 ...*.*..*.....*.*..*..*..*.*.*.*.....*.....*....*..*...*....*.........*....*....*...*......*..*..*...*..*...*.....*...*...*.*.*.........**..**.......*.......*...*...*.*.*........*....*..*..*...*.....*.*......**.**..**...*..*.**.....*....*.*.*..*..*..*.*..*.*..*......*..*..*.*......*...*.*...*....
output:
540
result:
ok 1 number(s): "540"
Test #4:
score: 0
Accepted
time: 130ms
memory: 135128kb
input:
975 434 .*......*...*....*......*..*...*...**....*....*.......*...*.....*..*..*.*.*..*.*..*..*.*....*.*.*..*...*.*.....*......*.*...*......*..*..*......**..**.......*...*.*..*..*.*.**....*.*.*.....*....**.*..*..**.*..*.....*.*......*..*...*..*...*....**...*....*..*.*.*...........*..*.**.*.*..*.*..**...
output:
5
result:
ok 1 number(s): "5"
Test #5:
score: 0
Accepted
time: 126ms
memory: 134676kb
input:
966 19 ..*.*.*........*.*..*.**..*....*..*..*....*.**..*.*.*..*.*.*..**....*.*.*....*.....*...........*.*..*.....*..*...*....*.*...*.*...*....*...*...*.*.*....*.*....**.*.......*....*.*.*...*..*..*..*.*...*...*...*..*..*..........*.*....*.*......*...*..**....*.*....**.....*..*..*..*.*....*...*..*.*....
output:
104
result:
ok 1 number(s): "104"
Test #6:
score: 0
Accepted
time: 134ms
memory: 137060kb
input:
973 199 ..**.*...*.*...*.*.*.*.**..*.*.*..*......*.....*.*.*..*...**.....*.*..*.*..*...*....*..*...*....*.*...*.*......*..*.*.*.*......**......*.*.*.*.*.*...*...*...*....*......*.*.*.*..*..*..*...*..*.*....*....*.*...*..*..*.*..**.**..*.**....*.*...*..**..**...*......*.....*.....*..*.*.......*.*.*.....
output:
10
result:
ok 1 number(s): "10"
Test #7:
score: 0
Accepted
time: 128ms
memory: 135628kb
input:
984 95 .....*.*...*....*..*....*.*....**.**......*....*.*.*.......*.....*.*..*....*..*....*.*.....*..*.......*.*......*.*....*.....*......*...*....*....*......*....*.*...*........*......*.*....*.*...*....*..**....*.*.*.**....*..*.*..*..*.*......*..*......*.*......*...*......*.......*...*....*...**.....
output:
21
result:
ok 1 number(s): "21"
Test #8:
score: -100
Time Limit Exceeded
input:
2996 2 ..*..*.....*..*.....*....**..*...........*..*........*..*..*.*..*..*.*.*.**.*.....**.*.......*.......*..*....*.....*..*.*.*....**.....*..**.....*.....*.......*.*.*.*....*...*..*.**......**..*.*...**..*..*......*..*.*...*......*.*.*.*...**.**..*.*........*.*..*...**......*.*..*.*..*....*.*.*.*...