QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#395184 | #8236. Snake Move | qawszx# | WA | 1ms | 3812kb | C++20 | 2.6kb | 2024-04-21 10:16:28 | 2024-04-21 10:16:29 |
Judging History
answer
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<random>
#include<array>
#include<assert.h>
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define dbg(x) cerr<<"In Line "<< __LINE__<<" the "<<#x<<" = "<<x<<'\n'
#define dpi(x,y) cerr<<"In Line "<<__LINE__<<" the "<<#x<<" = "<<x<<" ; "<<"the "<<#y<<" = "<<y<<'\n'
#define DE(fmt,...) fprintf(stderr, "Line %d : " fmt "\n",__LINE__,##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef pair<ll,int>pli;
typedef pair<ll,ll>pll;
typedef pair<int,ll>pil;
typedef vector<int>vi;
typedef vector<ll>vll;
typedef vector<pii>vpii;
typedef vector<pll>vpll;
template<typename T>T cmax(T &x, T y){return x=x>y?x:y;}
template<typename T>T cmin(T &x, T y){return x=x<y?x:y;}
template<typename T>
T &read(T &r){
r=0;bool w=0;char ch=getchar();
while(ch<'0'||ch>'9')w=ch=='-'?1:0,ch=getchar();
while(ch>='0'&&ch<='9')r=r*10+(ch^48),ch=getchar();
return r=w?-r:r;
}
template<typename T1,typename... T2>
void read(T1 &x,T2& ...y){read(x);read(y...);}
const int N=3010;
const int inf=0x3f3f3f3f;
int n,m,q;
char s[N][N];
pii a[100010];
int dis[N][N],co[N][N],pt[N][N],vis[N][N];
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
signed main(){
#ifdef do_while_true
// assert(freopen("data.in","r",stdin));
// assert(freopen("data.out","w",stdout));
#endif
read(n,m,q);
for(int i=1;i<=q;i++)read(a[i].fi,a[i].se),pt[a[i].fi][a[i].se]=i;
// for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)dis[i][j]=inf;
int sx=a[1].fi,sy=a[1].se;
dis[sx][sy]=0;
struct ele{
int x,y,w,d;
bool operator<(const ele &z)const{
return d>z.d;
}
};
queue<ele>Q;
Q.push({sx,sy,q,0});
while(!Q.empty()){
auto qt=Q.front();Q.pop();
int x=qt.x,y=qt.y,w=qt.w;
if(vis[x][y])continue;
vis[x][y]=1;
for(int i=0;i<4;i++){
int u=x+dx[i],v=y+dy[i];
if(u<1||v<1||u>n||v>m||s[u][v]=='#')continue;
int td=dis[x][y]+1;
int tc=co[x][y];
int nw=w;
if(pt[u][v]&&pt[u][v]+td<=w){
tc+=w-(pt[u][v]+td)+1;
nw-=w-(pt[u][v]+td)+1;
}
if(td+tc<dis[u][v]+co[u][v]){
dis[u][v]=td;
co[u][v]=tc;
Q.push({u,v,nw,td+tc});
}
}
}
ull sum=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)if(dis[i][j]!=inf){
ull x=dis[i][j]+co[i][j];
// cerr<<x<<' ';
sum+=x*x;
}
cout<<sum<<'\n';
#ifdef do_while_true
// cerr<<'\n'<<"Time:"<<1.0*clock()/CLOCKS_PER_SEC*1000<<" ms"<<'\n';
#endif
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3608kb
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: 3812kb
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: 3680kb
input:
5 5 3 1 2 1 1 2 1 ..... .###. .#.#. .###. .....
output:
368
result:
wrong answer 1st lines differ - expected: '407', found: '368'