QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#441591#8236. Snake MoveDixiky_215WA 942ms96700kbC++172.5kb2024-06-14 16:28:152024-06-14 16:28:16

Judging History

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

  • [2024-06-14 16:28:16]
  • 评测
  • 测评结果:WA
  • 用时:942ms
  • 内存:96700kb
  • [2024-06-14 16:28:15]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
const int MAXN=3e6+7;
const double eps=1e-11;
int n,m,k;
struct hhh
{
	int x,y;
	int dis,len,num;
	 bool operator < (const hhh x) const {  
			if(dis==x.dis) return len>x.len;
            return dis > x.dis;
        }   
}a[MAXN];
int dic_x[5]={0,-1,0,1,0};
int dic_y[5]={0,0,1,0,-1};
char b[4007];
ull dis[3007][3007];
bool pd[3007][3007];
int id[3007][3007];
bool vis[3007][3007];
inline void DJ()
{
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
			dis[i][j]=1e9+7;
	}
	priority_queue<hhh> q;
	dis[a[1].x][a[1].y]=0;

	hhh be=a[1];
	be.dis=0;be.len=k;be.num=0;
	q.push(be);
	be=a[2];
	dis[a[2].x][a[2].y]=k-1;
	be.len=2;be.dis=k-1;be.num=0;
	q.push(be);
	while(!q.empty())
	{
		hhh nowl=q.top();
		q.pop();
		if(vis[nowl.x][nowl.y]) continue;
		vis[nowl.x][nowl.y]=1;
		for(int i=1;i<=4;i++)
		{
			int xl=nowl.x+dic_x[i];
			int yl=nowl.y+dic_y[i];
			if(xl<1||yl<1||xl>n||yl>m) continue;
			if(pd[xl][yl]) continue;

			if(id[xl][yl])
			{
				
				if(dis[xl][yl]>max(0,nowl.len-id[xl][yl]-nowl.num)+dis[nowl.x][nowl.y]+1)
				{
					dis[xl][yl]=max(0,nowl.len-id[xl][yl]-nowl.num)+dis[nowl.x][nowl.y]+1;
					// if(nowl.x==2&&nowl.y==3) cerr<<xl<<" "<<yl<<" "<<dis[xl][yl]<<" asd"<<endl;
					if(!vis[xl][yl])
					{
						hhh u;
						u.x=xl;u.y=yl;
						u.dis=dis[xl][yl];
						if(nowl.len-id[xl][yl]-nowl.num>0)
						{
							u.len=id[xl][yl];
							u.num=0;
						}
						else
						{
							u.len=nowl.len;
							u.num=nowl.num+1;
						}
						q.push(u);
					}
				}
			}
			else
			{
				if(dis[xl][yl]>dis[nowl.x][nowl.y]+1)
				{
					dis[xl][yl]=dis[nowl.x][nowl.y]+1;
					if(!vis[xl][yl])
					{
						hhh u;
						u.x=xl;u.y=yl;
						u.dis=dis[xl][yl];
						u.len=nowl.len;
						u.num=nowl.num+1;
						q.push(u);
					}
				}
			}
		}
	}
}
int main()
{
	ios::sync_with_stdio(false);
    cout.tie(0);cin.tie(0);

	cin>>n>>m>>k;
	for(int i=1;i<=k;i++)
	{
		cin>>a[i].x>>a[i].y;
		id[a[i].x][a[i].y]=i;
	}
	for(int i=1;i<=n;i++)
	{
		cin>>b+1;
		for(int j=1;j<=m;j++)
		{
			if(b[j]=='#') pd[i][j]=1;
			else pd[i][j]=0;
		}
	}
	DJ();
	ull ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(vis[i][j]) ans+=dis[i][j]*dis[i][j];
			// cerr<<dis[i][j]<<' ';
		}
		// cerr<<endl;
	}
	cout<<ans;
	return 0;
}
/*
 4 5 5
 3 5
 3 4
 3 3
 3 2
 4 2
 .....
 .....
 .....
 .....

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 12036kb

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: 2ms
memory: 11716kb

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: 2ms
memory: 11812kb

input:

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

output:

407

result:

ok single line: '407'

Test #4:

score: 0
Accepted
time: 894ms
memory: 96440kb

input:

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

output:

35141960580077

result:

ok single line: '35141960580077'

Test #5:

score: 0
Accepted
time: 780ms
memory: 96148kb

input:

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

output:

17464052497724

result:

ok single line: '17464052497724'

Test #6:

score: 0
Accepted
time: 11ms
memory: 87900kb

input:

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

output:

255915

result:

ok single line: '255915'

Test #7:

score: 0
Accepted
time: 19ms
memory: 87808kb

input:

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

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 890ms
memory: 94348kb

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: 777ms
memory: 96440kb

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

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: 25ms
memory: 87576kb

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: 942ms
memory: 96700kb

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:

41693682092387

result:

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