QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#620245 | #8236. Snake Move | Hide_In_The_Shadow | WA | 399ms | 95012kb | C++23 | 3.0kb | 2024-10-07 17:08:45 | 2024-10-07 17:08:52 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define fio std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pii pair<int,int>
using namespace std;
template<typename T>void read(T &x){
x=0;
char c=getchar();
T ret=0;
while(!isdigit(c))ret|=!(c^'-'),c=getchar();
while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar();
if(ret)x=(~x)+1;
}
template<typename T,typename ...Args>
void read(T &x,Args &...xs){
read(x);read(xs...);
}
template<typename T>void print(T x){
if(x<0)putchar('-'),x=(~x)+1;
if(x>9)print(x/10);
putchar((x-x/10*10)^48);
}
template<typename T>void wr1(T x){
print(x);putchar(' ');
}
template<typename T>void wr2(T x){
print(x);putchar('\n');
}
const int N=3005;
int n,m,k,c1[]={1,0,-1,0},c2[]={0,1,0,-1},snac[N][N];
unsigned ll dis[N][N];
bool sna[N][N];
char mp[N][N];
queue<pair<pii,int>>q;
queue<pair<pii,int>>s;
pii sn[114514];
bool chek(int x,int y) {
if(x<1||y<1||x>n||y>m||mp[x][y]=='#'||sna[x][y])return 0;
return 1;
}
void bfs(int x,int y,int K) {
q.push({{x,y},1});
while(!q.empty()) {
int x=q.front().first.first,y=q.front().first.second,now=q.front().second;
q.pop();
while(!s.empty()&&s.front().second-now>=K-1) {
sna[s.front().first.first][s.front().first.second]=0;
s.pop();
}
for(int i=0;i<=3;++i) {
int X=x+c1[i],Y=y+c2[i];
if(chek(X,Y)) {
if(dis[X][Y]>dis[x][y]+1)dis[X][Y]=dis[x][y]+1,q.push({{X,Y},now-1}),s.push({{X,Y},now-1}),sna[X][Y]=1;
}
}
}
}
int main(){
read(n,m,k);
for(int i=1;i<=n;++i) {
for(int j=1;j<=m;++j) {
dis[i][j]=LONG_LONG_MAX;
}
}
for(int i=1;i<=k;++i){
int x,y;
read(x,y);
sn[i]=make_pair(x,y);
snac[x][y]=i;
}
for(int i=k;i>=1;--i) {
s.push({sn[i],i});
sna[sn[i].first][sn[i].second]=1;
}
for(int i=1;i<=n;++i) {
scanf("%s",mp[i]+1);
}
dis[sn[1].first][sn[1].second]=0;
bfs(sn[1].first,sn[1].second,k);
while(!s.empty()) {
sna[s.front().first.first][s.front().first.second]=0;
s.pop();
}
for(int i=0;i<=3;++i) {
int x=sn[1].first+c1[i],y=sn[1].second+c2[i];
if(snac[x][y]) {
int K=snac[x][y];
if(dis[x][y]>k-K+1) {
dis[x][y]=k-K+1;
for(int j=K-1;j>=1;--j) {
s.push({sn[j],j+1});
sna[sn[j].first][sn[j].second]=1;
}
bfs(x,y,K);
while(!s.empty()) {
sna[s.front().first.first][s.front().first.second]=0;
s.pop();
}
}
}
}
unsigned ll ans=0;
for(int i=1;i<=n;++i) {
for(int j=1;j<=m;++j) {
if(dis[i][j]>=LONG_LONG_MAX)continue;
ans+=dis[i][j]*dis[i][j];
}
}
print(ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 12120kb
input:
4 5 5 3 5 3 4 3 3 3 2 4 2 ..... ..... ..... .....
output:
293
result:
ok single line: '293'
Test #2:
score: 0
Accepted
time: 2ms
memory: 11860kb
input:
2 2 4 1 1 1 2 2 2 2 1 .. ..
output:
14
result:
ok single line: '14'
Test #3:
score: 0
Accepted
time: 0ms
memory: 11768kb
input:
5 5 3 1 2 1 1 2 1 ..... .###. .#.#. .###. .....
output:
407
result:
ok single line: '407'
Test #4:
score: 0
Accepted
time: 352ms
memory: 94728kb
input:
3000 2900 1 1882 526 ........................................................................................................#................................................................................................................................................................#................
output:
35141960580077
result:
ok single line: '35141960580077'
Test #5:
score: 0
Accepted
time: 399ms
memory: 93560kb
input:
2900 3000 1 1333 1773 .....#....#......#.#..#...#.....#.#.#.#....#...###.#..#.....##....####..#......#.......######.#........#..#......#...###.#.#..#.....#.#........##..#..#.#..#.###.#.#...#..#.##..#...#....#..#.##..#......#.######............#.#...#......#......#..#.#.#.#...#...#..##........#.###.....
output:
17464052497724
result:
ok single line: '17464052497724'
Test #6:
score: 0
Accepted
time: 27ms
memory: 89620kb
input:
3000 3000 1 2755 225 ##..#.##.....####..#...###.#.##.#.##.#......###.#####..#..####....#.#.####..##..##.#...#...##..#.#.##..#....##.#...#.....##.#...##.##.##..##..#######.####.####......##.##.#....#..#.....#..##.#.#...#.####..##.#..#...###..###.#.#...##.#.....###.####......##...#...#....#.#...#.#.#....
output:
255915
result:
ok single line: '255915'
Test #7:
score: 0
Accepted
time: 19ms
memory: 88776kb
input:
3000 2900 1 878 738 #.##.##..##.#.#.###.#...###.####.#.###.####.##.#.#####.#.####..#.#.###.###..####.####...###..####.########..##..#####.#....#####.#.#########..#.###.##.##.#####.#####.#.##..###..##.#####.#.############..##.###.##.##..########.#.###..###...######.####...#######.###.###..####.######...
output:
1
result:
ok single line: '1'
Test #8:
score: 0
Accepted
time: 298ms
memory: 90900kb
input:
2900 3000 10 2883 1758 2883 1759 2883 1760 2883 1761 2883 1762 2884 1762 2884 1763 2883 1763 2882 1763 2882 1764 ........................................................#............................#........................................................................................................
output:
49803365625286
result:
ok single line: '49803365625286'
Test #9:
score: 0
Accepted
time: 382ms
memory: 95012kb
input:
3000 3000 10 2015 1932 2015 1931 2015 1930 2015 1929 2016 1929 2017 1929 2018 1929 2018 1928 2018 1927 2017 1927 #...#...#..#.........#.......#####....#...###..#..###..###....##.....#..#..#...#.....##...##.#..#..##.###.........##.....#....#..##.##.#.#.##.#.#.#.....#....##.##.#..##....#....#...#.#......
output:
22509095749285
result:
ok single line: '22509095749285'
Test #10:
score: -100
Wrong Answer
time: 27ms
memory: 87676kb
input:
3000 2900 10 326 1781 325 1781 325 1782 325 1783 325 1784 324 1784 324 1783 323 1783 323 1782 324 1782 ##.#....#.###.######..#.#.....##.#.##..####.####.##..#..#.###.#####....##.#.##.#..###..##.###.##.#####.###..##.#..##..##.#..##.#.#.##...##..#.##.##........#..#..###.##.###.####.#..########.##.....#...
output:
41915
result:
wrong answer 1st lines differ - expected: '40571', found: '41915'