QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#844707#8236. Snake MoveaxujlsRE 0ms0kbC++141.2kb2025-01-06 10:18:002025-01-06 10:18:02

Judging History

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

  • [2025-01-06 10:18:02]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2025-01-06 10:18:00]
  • 提交

answer

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

const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};

int main() {
	int n, m, k; cin >> n >> m >> k;
	vector<pair<int, int>> coords(k + 1);
	vector<vector<int>> dp(n + 1, vector<int>(m + 1));
	for(int i = 1; i <= k; i++){
		cin >> coords[i].first >> coords[i].second;
		dp[coords[i].first][coords[i].second] += (k - i);
	}
	vector<vector<char>> cgrid(n + 1, vector<char>(m+1));
	for(int i = 1; i <= n; i++){
		string row; cin >> row;
		for(int j = 1; j <= m; j++){
			cgrid[i][j] = row[j-1];
		}
	}
	int d[n+1][m+1];
	memset(d, -1, sizeof d);
	vector<pair<int, int>> e[(n+1)*(n+1)];
	d[coords[1].first][coords[1].second] = 0;
	e[0].emplace_back(coords[1].first, coords[1].second);
	unsigned long long ans = 0;
	for(int i = 0; i < 9030024; i++){
		for(auto[x, y] : e[i]){
			ans += i * 1LL * i;
			for(int j = 0; j < 4; j++){
				int xx = x + DX[j]; int yy = y + DY[j];
				if(xx < 1 || yy < 1 || xx > n || yy > m || cgrid[xx][yy] == '#' || d[xx][yy] != -1){
					continue;
				}
				e[d[xx][yy] = max(i, dp[xx][yy]) + 1].emplace_back(xx, yy);
			}
		}
	}
	cout << ans << "\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

4 5 5
3 5
3 4
3 3
3 2
4 2
.....
.....
.....
.....

output:


result: