QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#749199#8236. Snake MoveCSQ#WA 1261ms120820kbC++171.6kb2024-11-14 23:01:152024-11-14 23:01:22

Judging History

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

  • [2024-11-14 23:01:22]
  • 评测
  • 测评结果:WA
  • 用时:1261ms
  • 内存:120820kb
  • [2024-11-14 23:01:15]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x) 
#define sz(x); (int) (x).size()

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
string grid[3000];
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
pii d[3000][3000];
int id[3000][3000];
int n,m,k;
bool check(int i,int j){
	return i>=0 && j>=0 && i<n && j<m && grid[i][j] != '#';
}
int main()
{
	cin>>n>>m>>k;
	vector<int>X(k),Y(k);
	for(int i=0;i<k;i++){
		cin>>X[i]>>Y[i];
		X[i]--;
		Y[i]--;
	}
	for(int i=0;i<n;i++)cin>>grid[i];
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			d[i][j] = {1e9,1e9};
		    id[i][j] = 1e9;
		}
	}
	for(int i=0;i<k;i++)id[X[i]][Y[i]] = i+1;
	d[X[0]][Y[0]] = {0,k};
	
	priority_queue<array<int,4>>pq;
	pq.push({0,-k,X[0],Y[0]});
	while(!pq.empty()){
		int x = pq.top()[2];
		int y = pq.top()[3];
		int d0 = -pq.top()[0];
		int len = -pq.top()[1];
		pq.pop();
		if(d[x][y] != make_pair(d0,len))continue;
		for(int j=0;j<4;j++){
			int xn = x+dx[j];
			int yn = y+dy[j];
			if(!check(xn,yn))continue;
			int need =(len-d0) - id[xn][yn];
			need = max(need,0);
			
			if(d[xn][yn] > make_pair(d0+need+1,len-need)){
				d[xn][yn] = {d0+need+1,len-need};
				pq.push({-d0-need-1,-len+need,xn,yn});
			}
		}
	}
	unsigned long long int ans = 0;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			//cout<<d[i][j].first<<" ";
			if(d[i][j].first == 1e9)continue;
			ans += d[i][j].first * d[i][j].first;
		}
		//cout<<'\n';
	}
	cout<<ans<<'\n';

	
	
	
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5744kb

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

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

input:

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

output:

407

result:

ok single line: '407'

Test #4:

score: 0
Accepted
time: 1197ms
memory: 120572kb

input:

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

output:

35141960580077

result:

ok single line: '35141960580077'

Test #5:

score: 0
Accepted
time: 1042ms
memory: 117488kb

input:

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

output:

17464052497724

result:

ok single line: '17464052497724'

Test #6:

score: 0
Accepted
time: 113ms
memory: 120704kb

input:

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

output:

255915

result:

ok single line: '255915'

Test #7:

score: 0
Accepted
time: 101ms
memory: 120460kb

input:

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

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 1214ms
memory: 117828kb

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

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

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

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

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:

41693681956189

result:

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