QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#696525 | #8236. Snake Move | GLLF234 | WA | 1797ms | 109732kb | C++20 | 2.7kb | 2024-10-31 23:07:01 | 2024-10-31 23:07:02 |
Judging History
answer
#include<bits/stdc++.h>
#define PIII pair<int,pair<int,int>>
using ll=long long;
using namespace std;
double a[100005];
int mp[3003][3003];
int dis[3003][3003];
int dis2[3003][3003];
const int inf=1e9+7;
int xx[5]={0,0,0,1,-1};
int yy[5]={0,1,-1,0,0};
int n,m,k;
#define ull unsigned long long
void bfs(int x,int y,int nx,int ny){
priority_queue<PIII,vector<PIII>,greater<PIII>> q;
q.push({0,{x,y}});
dis[x][y]=0;
while(!q.empty()){
auto it=q.top();
q.pop();
for(int i=1;i<=4;i++){
int a=it.second.first+xx[i],b=it.second.second+yy[i];
if(it.second.first==x&&it.second.second==y&&a==nx&&b==ny) continue;
if(a<=n&&a>0&&b<=m&&b>0&&mp[a][b]!=inf){
if(mp[a][b]>dis[it.second.first][it.second.second]+1){
if(mp[a][b]<dis[a][b]){
dis[a][b]=mp[a][b];
q.push({dis[a][b],{a,b}});
}
}
else if(dis[it.second.first][it.second.second]+1<dis[a][b]){
dis[a][b]=dis[it.second.first][it.second.second]+1;
q.push({dis[a][b],{a,b}});
}
}
}
}
}
void bfs2(int x,int y){
priority_queue<PIII,vector<PIII>,greater<PIII>> q;
q.push({0,{x,y}});
dis2[x][y]=0;
while(!q.empty()){
auto it=q.top();
q.pop();
for(int i=1;i<=4;i++){
int a=it.second.first+xx[i],b=it.second.second+yy[i];
if(a<=n&&a>0&&b<=m&&b>0&&mp[a][b]!=inf){
if(dis2[it.second.first][it.second.second]+1<dis2[a][b]){
dis2[a][b]=dis2[it.second.first][it.second.second]+1;
q.push({dis2[a][b],{a,b}});
}
}
}
}
}
void slove(){
memset(dis,0x7f,sizeof(dis));
memset(dis2,0x7f,sizeof(dis2));
cin>>n>>m>>k;
int sx,sy,sxx,syy;
for(int i=1;i<=k;i++){
int u,v;
cin>>u>>v;
mp[u][v]=k-i+1;
if(i==1) sx=u,sy=v;
if(i==2) sxx=u,syy=v;
}
for(int i=1;i<=n;i++){
string s;
cin>>s;
for(int j=0;j<m;j++){
if(s[j]=='#') mp[i][j+1]=inf;
}
}
bfs(sx,sy,sxx,syy);
bfs2(sx,sy);
ll ans=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(dis[i][j]==0x7f7f7f7f) continue;
ll p=min(dis[i][j],dis2[i][j]+k-2);
// cout<<p<<endl;
ans=ans+p*p;
}
}
cout<<ans<<endl;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int T=1;
// cin>>T;
while(T--){
slove();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 8ms
memory: 75156kb
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: 74604kb
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: 4ms
memory: 75876kb
input:
5 5 3 1 2 1 1 2 1 ..... .###. .#.#. .###. .....
output:
407
result:
ok single line: '407'
Test #4:
score: -100
Wrong Answer
time: 1797ms
memory: 109732kb
input:
3000 2900 1 1882 526 ........................................................................................................#................................................................................................................................................................#................
output:
35110644338148
result:
wrong answer 1st lines differ - expected: '35141960580077', found: '35110644338148'