QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#810398 | #8236. Snake Move | bitwim | RE | 431ms | 144944kb | C++14 | 2.1kb | 2024-12-11 22:01:17 | 2024-12-11 22:01:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
int a[3010][3010];
int f[3010][3010];
const array<int, 2> mov[4] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
unsigned int ans = 0;
void solve() {
int n, m, k;
cin >> n >> m >> k;
int x, y;
cin >> x >> y;
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= m; ++j) {
a[i][j] = 0;
f[i][j] = -1;
}
}
int ans = 0;
for(int i = 2; i <= k; ++i) {
int x1, y1;
cin >> x1 >> y1;
a[x1][y1] = k - i;
}
char c;
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= m; ++j) {
cin >> c;
if(c == '#') {
// cerr << 1 << '\n';
a[i][j] = -1;
}
// cout << a[i][j] << ' ';
}
// cout << '\n';
}
f[x][y] = 0;
queue<pair<int, int>> q;
q.push({x, y});
int time = 0;
while(!q.empty()) {
++time;
auto now = q.front();
q.pop();
// cerr << 1 << '\n';
int val = f[now.first][now.second];
for(int i = 0; i < 4; ++i) {
int nx = now.first + mov[i][0];
int ny = now.second + mov[i][1];
if(nx < 1 || nx > n || ny < 1 || ny > m) continue;
if(a[nx][ny] == -1) continue;
if(f[nx][ny] == -1 || f[nx][ny] > max(val + 1, a[nx][ny] + 1)) {
f[nx][ny] = max(val + 1, a[nx][ny] + 1);
q.push({nx, ny});
}
}
assert(time < 10000000);
}
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= m; ++j) {
// cout << f[i][j] << ' ';
if(f[i][j] != -1) {
ans += f[i][j] * f[i][j];
}
}
// cout << '\n';
}
cout << ans << '\n';
}
signed main() {
// cout<<fixed<<setprecision(12);
// cerr << mul()
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
// int t;
// cin >> t;
// while(t--) {
// solve();
// }
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5900kb
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: 5664kb
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: 5620kb
input:
5 5 3 1 2 1 1 2 1 ..... .###. .#.#. .###. .....
output:
407
result:
ok single line: '407'
Test #4:
score: 0
Accepted
time: 284ms
memory: 144940kb
input:
3000 2900 1 1882 526 ........................................................................................................#................................................................................................................................................................#................
output:
35141960580077
result:
ok single line: '35141960580077'
Test #5:
score: 0
Accepted
time: 431ms
memory: 140452kb
input:
2900 3000 1 1333 1773 .....#....#......#.#..#...#.....#.#.#.#....#...###.#..#.....##....####..#......#.......######.#........#..#......#...###.#.#..#.....#.#........##..#..#.#..#.###.#.#...#..#.##..#...#....#..#.##..#......#.######............#.#...#......#......#..#.#.#.#...#...#..##........#.###.....
output:
17464052497724
result:
ok single line: '17464052497724'
Test #6:
score: 0
Accepted
time: 143ms
memory: 144924kb
input:
3000 3000 1 2755 225 ##..#.##.....####..#...###.#.##.#.##.#......###.#####..#..####....#.#.####..##..##.#...#...##..#.#.##..#....##.#...#.....##.#...##.##.##..##..#######.####.####......##.##.#....#..#.....#..##.#.#...#.####..##.#..#...###..###.#.#...##.#.....###.####......##...#...#....#.#...#.#.#....
output:
255915
result:
ok single line: '255915'
Test #7:
score: 0
Accepted
time: 121ms
memory: 144892kb
input:
3000 2900 1 878 738 #.##.##..##.#.#.###.#...###.####.#.###.####.##.#.#####.#.####..#.#.###.###..####.####...###..####.########..##..#####.#....#####.#.#########..#.###.##.##.#####.#####.#.##..###..##.#####.#.############..##.###.##.##..########.#.###..###...######.####...#######.###.###..####.######...
output:
1
result:
ok single line: '1'
Test #8:
score: 0
Accepted
time: 315ms
memory: 142304kb
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: 426ms
memory: 144944kb
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: 138ms
memory: 144920kb
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: 123ms
memory: 140336kb
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
Runtime Error
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...