QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#670868#8236. Snake Movetest123WA 209ms121784kbC++141.9kb2024-10-24 07:15:252024-10-24 07:15:25

Judging History

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

  • [2024-10-24 07:15:25]
  • 评测
  • 测评结果:WA
  • 用时:209ms
  • 内存:121784kb
  • [2024-10-24 07:15:25]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int maxn=3005;
const int a[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
int read(){
    int ret=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
    while( isdigit(ch)){ret=(ret<<3)+(ret<<1)+(ch&15);ch=getchar();}
    return ret*f;
}
int n,m,k,hep_size;
struct node{
	int x,y; 
}que[maxn*maxn],p[100005];
int hep[100005],bel[maxn][maxn],dis[maxn][maxn];
bool vis[maxn][maxn];
void put(int id){
	hep[++hep_size]=id;int son=hep_size;
	while(son!=1&&hep[son]>hep[son>>1]) swap(hep[son],hep[son>>1]),son>>=1;
}
int get(){
	int ret=hep[1];hep[1]=hep[hep_size--];int fa=1,son;
	while((fa<<1)<=hep_size){
		if((fa<<1|1)>hep_size||hep[fa<<1]>hep[fa<<1|1]) son=fa<<1;else son=fa<<1|1;
		if(hep[son]>hep[fa]) swap(hep[son],hep[fa]),fa=son;else break;
	}
	return ret; 
}
bool check(int x,int y){
	return 1<=x&&x<=n&&1<=y&&y<=m&&!vis[x][y];
}
void BFS(){
	int hed=0,til=0;
	que[++til]=p[1];
	vis[p[1].x][p[1].y]=1;
	while(hed<til||hep_size){
		if(hed==til) que[++til]=p[get()];
		node now=que[++hed];
		if(hep_size&&dis[now.x][now.y]>=dis[p[hep[1]].x][p[hep[1]].y]){
			que[++til]=p[get()];
		}
		for(int p=0;p<4;++p){
			int x_=now.x+a[p][0],y_=now.y+a[p][1];
			if(!check(x_,y_)) continue;
			if(bel[x_][y_]){
				put(bel[x_][y_]);
				dis[x_][y_]=max(dis[now.x][now.y]+1,k-bel[x_][y_]+1);
			}else{
				que[++til]=(node){x_,y_};
				dis[x_][y_]=dis[now.x][now.y]+1;
			}
			vis[x_][y_]=1;
		}
	}
}
unsigned long long ans;
int main(){
	n=read(),m=read(),k=read();
	for(int i=1;i<=k;++i){
		p[i].x=read();
		p[i].y=read(); 
		bel[p[i].x][p[i].y]=i;
	}
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j){
			char ch=getchar();
			while(ch!='#'&&ch!='.') ch=getchar();
			if(ch=='#')	vis[i][j]=1;	
		}
	}	
	BFS();
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j){
			ans+=1ll*dis[i][j]*dis[i][j];
		}
	}
	printf("%llu\n",ans);
	return 0;
} 

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 10016kb

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

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

input:

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

output:

407

result:

ok single line: '407'

Test #4:

score: 0
Accepted
time: 116ms
memory: 120072kb

input:

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

output:

35141960580077

result:

ok single line: '35141960580077'

Test #5:

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

input:

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

output:

17464052497724

result:

ok single line: '17464052497724'

Test #6:

score: 0
Accepted
time: 71ms
memory: 18064kb

input:

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

output:

255915

result:

ok single line: '255915'

Test #7:

score: 0
Accepted
time: 62ms
memory: 17460kb

input:

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

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 118ms
memory: 120380kb

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: 209ms
memory: 102368kb

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: 61ms
memory: 17356kb

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: 54ms
memory: 19220kb

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: 120ms
memory: 121784kb

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:

41693682090305

result:

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