QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#125393 | #6739. Teleport | awellwell | TL | 163ms | 135644kb | C++14 | 2.2kb | 2023-07-16 16:58:24 | 2023-07-16 16:58:27 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define forn(i,p,q) for(int 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: 0ms
memory: 103376kb
input:
3 2 .*. .*. ...
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 4ms
memory: 103220kb
input:
3 3 .*. .*. ...
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 163ms
memory: 134356kb
input:
961 4 ...*.*..*.....*.*..*..*..*.*.*.*.....*.....*....*..*...*....*.........*....*....*...*......*..*..*...*..*...*.....*...*...*.*.*.........**..**.......*.......*...*...*.*.*........*....*..*..*...*.....*.*......**.**..**...*..*.**.....*....*.*.*..*..*..*.*..*.*..*......*..*..*.*......*...*.*...*....
output:
540
result:
ok 1 number(s): "540"
Test #4:
score: 0
Accepted
time: 126ms
memory: 135132kb
input:
975 434 .*......*...*....*......*..*...*...**....*....*.......*...*.....*..*..*.*.*..*.*..*..*.*....*.*.*..*...*.*.....*......*.*...*......*..*..*......**..**.......*...*.*..*..*.*.**....*.*.*.....*....**.*..*..**.*..*.....*.*......*..*...*..*...*....**...*....*..*.*.*...........*..*.**.*.*..*.*..**...
output:
5
result:
ok 1 number(s): "5"
Test #5:
score: 0
Accepted
time: 114ms
memory: 134612kb
input:
966 19 ..*.*.*........*.*..*.**..*....*..*..*....*.**..*.*.*..*.*.*..**....*.*.*....*.....*...........*.*..*.....*..*...*....*.*...*.*...*....*...*...*.*.*....*.*....**.*.......*....*.*.*...*..*..*..*.*...*...*...*..*..*..........*.*....*.*......*...*..**....*.*....**.....*..*..*..*.*....*...*..*.*....
output:
104
result:
ok 1 number(s): "104"
Test #6:
score: 0
Accepted
time: 98ms
memory: 135008kb
input:
973 199 ..**.*...*.*...*.*.*.*.**..*.*.*..*......*.....*.*.*..*...**.....*.*..*.*..*...*....*..*...*....*.*...*.*......*..*.*.*.*......**......*.*.*.*.*.*...*...*...*....*......*.*.*.*..*..*..*...*..*.*....*....*.*...*..*..*.*..**.**..*.**....*.*...*..**..**...*......*.....*.....*..*.*.......*.*.*.....
output:
10
result:
ok 1 number(s): "10"
Test #7:
score: 0
Accepted
time: 122ms
memory: 135644kb
input:
984 95 .....*.*...*....*..*....*.*....**.**......*....*.*.*.......*.....*.*..*....*..*....*.*.....*..*.......*.*......*.*....*.....*......*...*....*....*......*....*.*...*........*......*.*....*.*...*....*..**....*.*.*.**....*..*.*..*..*.*......*..*......*.*......*...*......*.......*...*....*...**.....
output:
21
result:
ok 1 number(s): "21"
Test #8:
score: -100
Time Limit Exceeded
input:
2996 2 ..*..*.....*..*.....*....**..*...........*..*........*..*..*.*..*..*.*.*.**.*.....**.*.......*.......*..*....*.....*..*.*.*....**.....*..**.....*.....*.......*.*.*.*....*...*..*.**......**..*.*...**..*..*......*..*.*...*......*.*.*.*...**.**..*.*........*.*..*...**......*.*..*.*..*....*.*.*.*...