QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#395222#8236. Snake Moveqawszx#WA 367ms86848kbC++202.5kb2024-04-21 11:08:062024-04-21 11:08:06

Judging History

你现在查看的是最新测评结果

  • [2024-04-21 11:08:06]
  • 评测
  • 测评结果:WA
  • 用时:367ms
  • 内存:86848kb
  • [2024-04-21 11:08:06]
  • 提交

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 pt[N][N],vis[N][N];
int ans[N][N];
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
void dij(){
	struct ele{
		int x,y,d;
		bool operator<(const ele &z)const{
			return d>z.d;
		}
	};
	memset(ans,0x3f,sizeof(ans));
	queue<ele>Q;
	ans[a[1].fi][a[1].se]=0;Q.push({a[1].fi,a[1].se,0});
	while(!Q.empty()){
		auto qt=Q.front();Q.pop();
		int x=qt.x,y=qt.y;
		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 w=ans[x][y]+1;
			if(pt[u][v])
				cmax(w,q-pt[u][v]+1);
			if(ans[u][v]>w){
				ans[u][v]=w;
				Q.push({u,v,w});
			}
		}
	}
}
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);
	dij();
	ull sum=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)if(ans[i][j]!=inf){
			ull x=ans[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: 0ms
memory: 41208kb

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: 3ms
memory: 41432kb

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: 41148kb

input:

5 5 3
1 2
1 1
2 1
.....
.###.
.#.#.
.###.
.....

output:

407

result:

ok single line: '407'

Test #4:

score: 0
Accepted
time: 298ms
memory: 85152kb

input:

3000 2900 1
1882 526
........................................................................................................#................................................................................................................................................................#................

output:

35141960580077

result:

ok single line: '35141960580077'

Test #5:

score: 0
Accepted
time: 367ms
memory: 83076kb

input:

2900 3000 1
1333 1773
.....#....#......#.#..#...#.....#.#.#.#....#...###.#..#.....##....####..#......#.......######.#........#..#......#...###.#.#..#.....#.#........##..#..#.#..#.###.#.#...#..#.##..#...#....#..#.##..#......#.######............#.#...#......#......#..#.#.#.#...#...#..##........#.###.....

output:

17464052497724

result:

ok single line: '17464052497724'

Test #6:

score: 0
Accepted
time: 29ms
memory: 52180kb

input:

3000 3000 1
2755 225
##..#.##.....####..#...###.#.##.#.##.#......###.#####..#..####....#.#.####..##..##.#...#...##..#.#.##..#....##.#...#.....##.#...##.##.##..##..#######.####.####......##.##.#....#..#.....#..##.#.#...#.####..##.#..#...###..###.#.#...##.#.....###.####......##...#...#....#.#...#.#.#....

output:

255915

result:

ok single line: '255915'

Test #7:

score: 0
Accepted
time: 16ms
memory: 50864kb

input:

3000 2900 1
878 738
#.##.##..##.#.#.###.#...###.####.#.###.####.##.#.#####.#.####..#.#.###.###..####.####...###..####.########..##..#####.#....#####.#.#########..#.###.##.##.#####.#####.#.##..###..##.#####.#.############..##.###.##.##..########.#.###..###...######.####...#######.###.###..####.######...

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 311ms
memory: 85664kb

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: -100
Wrong Answer
time: 367ms
memory: 86848kb

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:

22509095749317

result:

wrong answer 1st lines differ - expected: '22509095749285', found: '22509095749317'