QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#749210 | #8236. Snake Move | CSQ# | WA | 1240ms | 120588kb | C++17 | 1.6kb | 2024-11-14 23:03:35 | 2024-11-14 23:03:36 |
Judging History
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 * 1LL* d[i][j].first;
}
//cout<<'\n';
}
cout<<ans<<'\n';
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5732kb
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: 5720kb
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: 5756kb
input:
5 5 3 1 2 1 1 2 1 ..... .###. .#.#. .###. .....
output:
407
result:
ok single line: '407'
Test #4:
score: 0
Accepted
time: 1169ms
memory: 120576kb
input:
3000 2900 1 1882 526 ........................................................................................................#................................................................................................................................................................#................
output:
35141960580077
result:
ok single line: '35141960580077'
Test #5:
score: 0
Accepted
time: 1040ms
memory: 118684kb
input:
2900 3000 1 1333 1773 .....#....#......#.#..#...#.....#.#.#.#....#...###.#..#.....##....####..#......#.......######.#........#..#......#...###.#.#..#.....#.#........##..#..#.#..#.###.#.#...#..#.##..#...#....#..#.##..#......#.######............#.#...#......#......#..#.#.#.#...#...#..##........#.###.....
output:
17464052497724
result:
ok single line: '17464052497724'
Test #6:
score: 0
Accepted
time: 99ms
memory: 120396kb
input:
3000 3000 1 2755 225 ##..#.##.....####..#...###.#.##.#.##.#......###.#####..#..####....#.#.####..##..##.#...#...##..#.#.##..#....##.#...#.....##.#...##.##.##..##..#######.####.####......##.##.#....#..#.....#..##.#.#...#.####..##.#..#...###..###.#.#...##.#.....###.####......##...#...#....#.#...#.#.#....
output:
255915
result:
ok single line: '255915'
Test #7:
score: 0
Accepted
time: 95ms
memory: 120496kb
input:
3000 2900 1 878 738 #.##.##..##.#.#.###.#...###.####.#.###.####.##.#.#####.#.####..#.#.###.###..####.####...###..####.########..##..#####.#....#####.#.#########..#.###.##.##.#####.#####.#.##..###..##.#####.#.############..##.###.##.##..########.#.###..###...######.####...#######.###.###..####.######...
output:
1
result:
ok single line: '1'
Test #8:
score: 0
Accepted
time: 1193ms
memory: 118452kb
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: 1043ms
memory: 120588kb
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: 126ms
memory: 120408kb
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: 95ms
memory: 119196kb
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: 1240ms
memory: 120520kb
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'