QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#368340 | #8236. Snake Move | wdw | WA | 0ms | 3800kb | C++20 | 2.8kb | 2024-03-27 01:05:45 | 2024-03-27 01:05:47 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int N = 5e5 + 5;
const int mod = 1e9+7;
const double eps =0.00001;
#define int long long
#define ull unsigned long long
#define endl '\n'
using i64 = int64_t;
int ksm(int a,int b){
int ans=1;
while(b){
if(b%2)ans=ans*a%mod;
a=a*a%mod;
b/=2;
}
return ans;
}
struct node{
int cnt=0,x,y,k;
inline bool operator<(const node &x)const {
return cnt>x.cnt;
}
};
vector<vector<char>>pic;
vector<vector<int>>idx,dis,vis;
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
void solve() {
int n,m,k;
cin>>n>>m>>k;
pic=vector<vector<char>>(n+5,vector<char>(m+5));
vis=dis=idx=vector<vector<int>>(n+5,vector<int>(m+5));
int x,y;
for(int i=1,x1,y1;i<=k;i++){
if(i==1){
cin>>x>>y;
idx[x][y]=i;
}else{
cin>>x1>>y1;
idx[x1][y1]=i;
}
}
priority_queue<node>q;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>pic[i][j];
dis[i][j]=1e9;
if(idx[i][j]>1){
dis[i][j]=max(k-2+idx[i][j]-1,1ll*0);
//q.push({ dis[i][j],i,j,2});
}
}
}
dis[x][y]=0;
q.push({0,x,y,k});
while(!q.empty()){
auto y=q.top();
q.pop();
if(vis[y.x][y.y])continue;
vis[y.x][y.y]=1;
for(int i=0;i<4;i++){
int x1=y.x+dx[i],y1=y.y+dy[i];
if(x1<1||x1>n||y1<1||y1>m||pic[x1][y1]=='#')continue;
if(idx[x1][y1]){
if(y.k-idx[x1][y1]-y.cnt<=0){
if(dis[x1][y1]>dis[y.x][y.y]+1){
dis[x1][y1]=dis[y.x][y.y]+1;
q.push({dis[x1][y1],x1,y1,y.k});
}
}else{
int p=y.k-idx[x1][y1]-y.cnt;
if(dis[x1][y1]>dis[y.x][y.y]+1+p){
dis[x1][y1]=dis[y.x][y.y]+1+p;
q.push({dis[x1][y1],x1,y1,y.k-p});
}
}
}else{
if(dis[x1][y1]>dis[y.x][y.y]+1){
dis[x1][y1]=dis[y.x][y.y]+1;
q.push({dis[x1][y1],x1,y1,y.k});
}
}
}
}
ull ans=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(dis[i][j]==1e9)continue;
ans+=(ull)(dis[i][j]*dis[i][j]);
}
}
cout<<ans<<endl;
}
signed main() {
std::ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cout<<fixed<<setprecision(11);
int T = 1;
// cin >> T;
while (T--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3800kb
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: 3540kb
input:
2 2 4 1 1 1 2 2 2 2 1 .. ..
output:
14
result:
ok single line: '14'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3608kb
input:
5 5 3 1 2 1 1 2 1 ..... .###. .#.#. .###. .....
output:
832
result:
wrong answer 1st lines differ - expected: '407', found: '832'