QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#395219#8236. Snake Moveqawszx#WA 316ms86280kbC++203.1kb2024-04-21 11:02:192024-04-21 11:02:20

Judging History

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

  • [2024-04-21 11:02:20]
  • 评测
  • 测评结果:WA
  • 用时:316ms
  • 内存:86280kb
  • [2024-04-21 11:02:19]
  • 提交

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],pt[N][N],vis[N][N];
int ans[N][N];
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
void BFS1(){
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)ans[i][j]=dis[i][j]=inf;
	queue<pii>Q;
	dis[a[1].fi][a[1].se]=0;
	Q.emplace(a[1].fi,a[1].se);
	while(!Q.empty()){
		auto qt=Q.front();Q.pop();
		int x=qt.fi,y=qt.se;
		if(pt[x][y]>1)continue;
		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;
			if(dis[u][v]==inf){
				dis[u][v]=dis[x][y]+1;
				Q.emplace(u,v);
			}
		}
	}
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)if(!pt[i][j])cmin(ans[i][j],dis[i][j]);
}
void BFS2(){
	struct ele{
		int x,y,d;
		bool operator<(const ele &z)const{
			return d>z.d;
		}
	};
	queue<ele>Q;
	for(int i=1;i<=q;i++){
		int x=a[i].fi,y=a[i].se;
		if(dis[x][y]!=inf){
			int w=max(0,q-(i+dis[x][y])+1);
			ans[x][y]=w+dis[x][y];
			Q.push({x,y,ans[x][y]});
		}
	}
	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;
			if(ans[u][v]>ans[x][y]+1){
				ans[u][v]=ans[x][y]+1;
				Q.push({u,v,ans[u][v]});
			}
		}
	}
}
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);
	BFS1();
	BFS2();
	ans[a[1].fi][a[1].se]=0;
	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: 7808kb

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: 1ms
memory: 5828kb

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: 1ms
memory: 5880kb

input:

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

output:

407

result:

ok single line: '407'

Test #4:

score: 0
Accepted
time: 188ms
memory: 83348kb

input:

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

output:

35141960580077

result:

ok single line: '35141960580077'

Test #5:

score: 0
Accepted
time: 294ms
memory: 84040kb

input:

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

output:

17464052497724

result:

ok single line: '17464052497724'

Test #6:

score: 0
Accepted
time: 31ms
memory: 85404kb

input:

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

output:

255915

result:

ok single line: '255915'

Test #7:

score: 0
Accepted
time: 31ms
memory: 86280kb

input:

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

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 196ms
memory: 84308kb

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: 316ms
memory: 85984kb

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: 27ms
memory: 85932kb

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: 38ms
memory: 84628kb

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
Wrong Answer
time: 218ms
memory: 85676kb

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...

output:

41693809339129

result:

wrong answer 1st lines differ - expected: '41693682087973', found: '41693809339129'