QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#730616 | #8236. Snake Move | xinlengweishang | WA | 394ms | 460520kb | C++20 | 1.6kb | 2024-11-09 20:50:10 | 2024-11-09 20:50:10 |
Judging History
answer
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll dp[3010][3010],f[3010][3010],t[3010][3010],flag[3010][3010];
char s[3010][3010];
ll n,m,k;
struct Node{
ll x,y;
}qu[20000000];
ll px[4]={1,-1,0,0};
ll py[4]={0,0,1,-1};
ll ans;
void bfs(ll x,ll y){
ll l=1,r=1;
qu[l].x=x;qu[l].y=y;
while(l<=r){
Node t=qu[l];
for(ll i=0;i<4;i++){
ll tx=t.x+px[i],ty=t.y+py[i];
if(tx>n||tx<=0||ty>m||ty<=0) continue;
if(s[tx-1][ty-1]=='#') continue;
//dp[tx][ty]=min(dp[tx][ty], s+1+dp[t.x][t.y]);
if(dp[tx][ty]>1+dp[t.x][t.y]){
if(dp[tx][ty]==f[tx][ty]) continue;
dp[tx][ty]=max(1+dp[t.x][t.y],f[tx][ty]);
//flag[tx][ty]=1;
r++;
qu[r].x=tx;qu[r].y=ty;
}
}
l++;
}
}
void slove(){
ll x0,y0;
scanf("%lld%lld%lld",&n,&m,&k);
for(ll i=1;i<=3000;i++){
for(ll q=1;q<=3000;q++){
dp[i][q]=1000000010;
}
}
for(ll i=1;i<=k;i++){
ll x,y;
scanf("%lld%lld",&x,&y);
if(i==1) x0=x,y0=y;
f[x][y]=k-i+1;
}
dp[x0][y0]=0;
for(ll i=0;i<n;i++){
scanf("%s",s[i]);
}
bfs(x0,y0);
}
int main(){
ll T=1;
while(T--) slove();
//ll MOD=1<<64;
for(ll i=1;i<=n;i++)
for(ll j=1;j<=m;j++){
ll s=dp[i][j]!=1000000010 ? dp[i][j] : 0;
ans+=s*s;
//ans%=MOD;
}
//cout<<1;
printf("%lld", ans);
//cout<<ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 79164kb
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: 7ms
memory: 80376kb
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: 78840kb
input:
5 5 3 1 2 1 1 2 1 ..... .###. .#.#. .###. .....
output:
407
result:
ok single line: '407'
Test #4:
score: 0
Accepted
time: 179ms
memory: 225000kb
input:
3000 2900 1 1882 526 ........................................................................................................#................................................................................................................................................................#................
output:
35141960580077
result:
ok single line: '35141960580077'
Test #5:
score: 0
Accepted
time: 255ms
memory: 179992kb
input:
2900 3000 1 1333 1773 .....#....#......#.#..#...#.....#.#.#.#....#...###.#..#.....##....####..#......#.......######.#........#..#......#...###.#.#..#.....#.#........##..#..#.#..#.###.#.#...#..#.##..#...#....#..#.##..#......#.######............#.#...#......#......#..#.#.#.#...#...#..##........#.###.....
output:
17464052497724
result:
ok single line: '17464052497724'
Test #6:
score: 0
Accepted
time: 12ms
memory: 90272kb
input:
3000 3000 1 2755 225 ##..#.##.....####..#...###.#.##.#.##.#......###.#####..#..####....#.#.####..##..##.#...#...##..#.#.##..#....##.#...#.....##.#...##.##.##..##..#######.####.####......##.##.#....#..#.....#..##.#.#...#.####..##.#..#...###..###.#.#...##.#.....###.####......##...#...#....#.#...#.#.#....
output:
255915
result:
ok single line: '255915'
Test #7:
score: 0
Accepted
time: 26ms
memory: 87620kb
input:
3000 2900 1 878 738 #.##.##..##.#.#.###.#...###.####.#.###.####.##.#.#####.#.####..#.#.###.###..####.####...###..####.########..##..#####.#....#####.#.#########..#.###.##.##.#####.#####.#.##..###..##.#####.#.############..##.###.##.##..########.#.###..###...######.####...#######.###.###..####.######...
output:
1
result:
ok single line: '1'
Test #8:
score: 0
Accepted
time: 230ms
memory: 225388kb
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: 277ms
memory: 186060kb
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: 27ms
memory: 92396kb
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: 26ms
memory: 87184kb
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: 394ms
memory: 460520kb
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:
8028965073773
result:
wrong answer 1st lines differ - expected: '41693682087973', found: '8028965073773'