QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#548097 | #8236. Snake Move | WhaleAtCola | WA | 318ms | 147544kb | C++17 | 1.6kb | 2024-09-05 15:27:20 | 2024-09-05 15:27:20 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define debug(...) fprintf(stderr,__VA_ARGS__)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
inline ll read(){
ll x=0;bool w=0;char c=getchar();
while(c>'9'||c<'0') w|=c=='-',c=getchar();
while(c>='0'&&c<='9') x=x*10+(c-'0'),c=getchar();
return w?-x:x;
}
const int inf=0x3f3f3f3f;
inline int crd(){
char c=getchar();
while(c!='#'&&c!='.') c=getchar();
return c=='#'?inf:0;
}
const int N=3030,L=101010;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
int ex[L],ey[L],g[N][N],f[N][N],qx[N*N],qy[N*N],ok[L];
inline void rmain(){
int n=read(),m=read(),l=read(),ql,qr,px,py,tx,ty,tt;
for(int i=1;i<=l;++i) ex[i]=read(),ey[i]=read();
memset(g,0x3f,sizeof g),memset(f,0x3f,sizeof f);
for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) g[i][j]=crd();
for(int i=1;i<=l;++i) g[ex[i]][ey[i]]=l-i+1;
// for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) debug("%2d%c",g[i][j]," \n"[j==m]);
qx[ql=qr=1]=ex[1],qy[1]=ey[1],f[ex[1]][ey[1]]=0;
while(ql<=qr){
px=qx[ql],py=qy[ql++],tt=f[px][py]+1;
if(tt<=l&&ok[tt]==1) qx[++qr]=ex[tt],qy[qr]=ey[tt],ok[tt]=2;
for(int k=0;k<4;++k){
tx=px+dx[k],ty=py+dy[k];
if(f[tx][ty]>tt){
if(g[tx][ty]<=tt) qx[++qr]=tx,qy[qr]=ty,f[tx][ty]=tt;
else if(g[tx][ty]!=inf) ok[l-g[tx][ty]+1]=1,f[tx][ty]=g[tx][ty];
}
}
}
// for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) debug("%2d%c",f[i][j]," \n"[j==m]);
ull ans=0;
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j)
if(f[i][j]!=inf) ans+=((ull)f[i][j])*f[i][j];
printf("%lld\n",ans);
}
signed main(){
// int T=read();while(T--)
rmain();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 76496kb
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: 0ms
memory: 77500kb
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: 3ms
memory: 76352kb
input:
5 5 3 1 2 1 1 2 1 ..... .###. .#.#. .###. .....
output:
407
result:
ok single line: '407'
Test #4:
score: 0
Accepted
time: 149ms
memory: 145304kb
input:
3000 2900 1 1882 526 ........................................................................................................#................................................................................................................................................................#................
output:
35141960580077
result:
ok single line: '35141960580077'
Test #5:
score: 0
Accepted
time: 318ms
memory: 124812kb
input:
2900 3000 1 1333 1773 .....#....#......#.#..#...#.....#.#.#.#....#...###.#..#.....##....####..#......#.......######.#........#..#......#...###.#.#..#.....#.#........##..#..#.#..#.###.#.#...#..#.##..#...#....#..#.##..#......#.######............#.#...#......#......#..#.#.#.#...#...#..##........#.###.....
output:
17464052497724
result:
ok single line: '17464052497724'
Test #6:
score: 0
Accepted
time: 76ms
memory: 80008kb
input:
3000 3000 1 2755 225 ##..#.##.....####..#...###.#.##.#.##.#......###.#####..#..####....#.#.####..##..##.#...#...##..#.#.##..#....##.#...#.....##.#...##.##.##..##..#######.####.####......##.##.#....#..#.....#..##.#.#...#.####..##.#..#...###..###.#.#...##.#.....###.####......##...#...#....#.#...#.#.#....
output:
255915
result:
ok single line: '255915'
Test #7:
score: 0
Accepted
time: 65ms
memory: 78664kb
input:
3000 2900 1 878 738 #.##.##..##.#.#.###.#...###.####.#.###.####.##.#.#####.#.####..#.#.###.###..####.####...###..####.########..##..#####.#....#####.#.#########..#.###.##.##.#####.#####.#.##..###..##.#####.#.############..##.###.##.##..########.#.###..###...######.####...#######.###.###..####.######...
output:
1
result:
ok single line: '1'
Test #8:
score: 0
Accepted
time: 136ms
memory: 144800kb
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: 303ms
memory: 124680kb
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: 0
Accepted
time: 71ms
memory: 79520kb
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:
40571
result:
ok single line: '40571'
Test #11:
score: 0
Accepted
time: 63ms
memory: 75828kb
input:
2900 3000 10 2447 135 2447 136 2447 137 2447 138 2447 139 2447 140 2448 140 2448 139 2449 139 2449 138 .#.##.##..#.###########.#####.###....#####.########..##..#.####.##.##.####.####..#.#####.##.#.#.###.##.#.##.####..##.#.####..###..###...##...##.#####.#####.#...#####.####..##.##.#.#..#..####.##..##...
output:
2705
result:
ok single line: '2705'
Test #12:
score: -100
Wrong Answer
time: 238ms
memory: 147544kb
input:
3000 3000 100 2573 1917 2572 1917 2572 1916 2573 1916 2574 1916 2574 1915 2573 1915 2572 1915 2571 1915 2571 1914 2570 1914 2570 1915 2569 1915 2569 1916 2568 1916 2568 1917 2569 1917 2570 1917 2570 1916 2571 1916 2571 1917 2571 1918 2570 1918 2569 1918 2569 1919 2570 1919 2571 1919 2571 1920 2572 1...
output:
13284756578809
result:
wrong answer 1st lines differ - expected: '41693682087973', found: '13284756578809'