QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#614553 | #8236. Snake Move | 7islands | TL | 2610ms | 963080kb | C++17 | 2.5kb | 2024-10-05 16:33:35 | 2024-10-05 16:33:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int inf=0x3f3f3f3f;
const ll infll=0x3f3f3f3f3f3f3f3f;
//#define int long long
#define pii pair <int,int>
#define ld long double
#define endl "\n"
const int N=10000050;
struct edge{
int to;
int w;
};
int disf[N];
vector<edge> e[N];//邻接表存图
int dis[N];
priority_queue <pii,vector<pii>,greater<pii>> q;
void Dijkstra(int s){
memset (dis,0x3f,sizeof (dis));
q.push({0,s});
dis[s]=0;
while (!q.empty()){
pii tmp=q.top();
q.pop();
int u=tmp.second;
int d=tmp.first;
if(d>dis[u])continue;
int len=e[u].size();
for (int i=0;i<len;i++){
int v=e[u][i].to;
int w=e[u][i].w;
if (dis[u]+w<=disf[v]){
dis[v]=disf[v];
q.push({dis[v],v});
}
else if(dis[v]>dis[u]+w){
dis[v]=dis[u]+w;
q.push({dis[v],v});
}
}
}
}
char a[3050][3050];
int dx[10]={1,-1,0,0};
int dy[10]={0,0,1,-1};
signed main (){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int n,m,k;
cin >>n>>m>>k;
int hdx,hdy;
cin >>hdx>>hdy;
for (int i=2;i<=k;i++){
int x,y;
cin >>x>>y;
disf[(x-1)*m+y]=k-i+1;
}
for (int i=1;i<=n;i++){
for (int j=1;j<=m;j++){
cin >>a[i][j];
}
}
for (int i=1;i<=n;i++){
for (int j=1;j<=m;j++){
int u=(i-1)*m+j;
if (a[i][j]=='#')continue;
// cerr <<i<<j<<" ";
for (int k=0;k<=3;k++){
int x=dx[k]+i;
int y=dy[k]+j;
// cerr <<x<<" "<<y<<" "<<a[x][y]<<endl;
if (x>0&&x<=n&&y>0&&y<=m&&a[x][y]=='.'){
//cerr <<x<<" "<<y<<endl;
// cout <<"touch"<<endl;
int v=(x-1)*m+y;
e[u].push_back({v,1});
e[v].push_back({u,1});
}
}
}
}
//cout <<(hdx-1)*m+hdy<<endl;
Dijkstra((hdx-1)*m+hdy);
unsigned long long ans=0;
for (int i=1;i<=n*m;i++){
// cerr <<dis[i]<<" ";
//if (i%m==0)cerr <<endl;
if (dis[i]!=inf)ans+=dis[i]*dis[i];
}
// for (int i=1;i<=n*m;i++){
// cout <<disf[i]<<" ";
// if (i%m==0)cout <<endl;
// }
cout <<ans<<endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 31ms
memory: 278152kb
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: 20ms
memory: 280124kb
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: 36ms
memory: 278092kb
input:
5 5 3 1 2 1 1 2 1 ..... .###. .#.#. .###. .....
output:
407
result:
ok single line: '407'
Test #4:
score: 0
Accepted
time: 2326ms
memory: 959464kb
input:
3000 2900 1 1882 526 ........................................................................................................#................................................................................................................................................................#................
output:
35141960580077
result:
ok single line: '35141960580077'
Test #5:
score: 0
Accepted
time: 1991ms
memory: 681080kb
input:
2900 3000 1 1333 1773 .....#....#......#.#..#...#.....#.#.#.#....#...###.#..#.....##....####..#......#.......######.#........#..#......#...###.#.#..#.....#.#........##..#..#.#..#.###.#.#...#..#.##..#...#....#..#.##..#......#.######............#.#...#......#......#..#.#.#.#...#...#..##........#.###.....
output:
17464052497724
result:
ok single line: '17464052497724'
Test #6:
score: 0
Accepted
time: 638ms
memory: 506040kb
input:
3000 3000 1 2755 225 ##..#.##.....####..#...###.#.##.#.##.#......###.#####..#..####....#.#.####..##..##.#...#...##..#.#.##..#....##.#...#.....##.#...##.##.##..##..#######.####.####......##.##.#....#..#.....#..##.#.#...#.####..##.#..#...###..###.#.#...##.#.....###.####......##...#...#....#.#...#.#.#....
output:
255915
result:
ok single line: '255915'
Test #7:
score: 0
Accepted
time: 326ms
memory: 369216kb
input:
3000 2900 1 878 738 #.##.##..##.#.#.###.#...###.####.#.###.####.##.#.#####.#.####..#.#.###.###..####.####...###..####.########..##..#####.#....#####.#.#########..#.###.##.##.#####.#####.#.##..###..##.#####.#.############..##.###.##.##..########.#.###..###...######.####...#######.###.###..####.######...
output:
1
result:
ok single line: '1'
Test #8:
score: 0
Accepted
time: 2610ms
memory: 963080kb
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: 2015ms
memory: 694960kb
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: 581ms
memory: 501680kb
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: 340ms
memory: 370448kb
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
Time Limit Exceeded
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...