QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#554672 | #5600. Restaurant Opening | nfls_vjudge | AC ✓ | 10ms | 3828kb | C++14 | 884b | 2024-09-09 14:14:39 | 2024-09-09 14:14:40 |
Judging History
answer
// Hydro submission #66de918673d92a7adbef7f7d@1725862470545
// for test
#include <bits/stdc++.h>
using namespace std;
long long distance(const vector<vector<int>> grid, const int& x, const int& y) {
int n = grid.size(), m = grid[0].size();
long long dis = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
dis = dis + grid[i][j] * (abs(x - i) + abs (y - j));
return dis;
}
int main() {
int n, m;
long long res = LONG_LONG_MAX;
cin >> n >> m;
vector<vector<int>> grid(n, vector<int>(m)); // n = row, m = col
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> grid[i][j];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (distance(grid, i, j) < res)
res = distance(grid, i, j);
cout << res;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3572kb
input:
2 2 1 2 3 4
output:
7
result:
ok single line: '7'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
1 10 3 49 4 31 10 31 50 24 10 42
output:
591
result:
ok single line: '591'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3588kb
input:
7 42 22 32 37 13 25 11 36 11 37 45 17 26 9 35 2 17 1 32 12 19 12 45 38 45 23 43 13 41 38 30 38 16 30 34 44 36 27 23 10 28 43 31 3 25 37 44 34 15 49 9 21 36 34 38 11 16 24 39 8 34 31 11 18 3 48 39 40 25 30 15 37 40 23 18 22 9 41 23 38 37 29 4 16 8 47 19 31 15 11 41 14 4 7 37 19 13 14 18 21 9 24 46 40...
output:
85301
result:
ok single line: '85301'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3812kb
input:
10 37 30 45 39 14 40 35 2 13 44 5 35 37 22 31 8 11 6 33 10 5 8 49 34 31 0 4 22 46 0 1 20 22 31 3 26 19 9 1 45 6 20 0 15 2 33 33 39 16 31 26 20 26 1 4 47 30 29 6 21 25 44 39 20 47 27 33 8 19 10 7 34 40 20 22 33 20 39 20 28 28 37 37 35 9 27 45 29 12 26 23 28 0 14 48 29 30 11 9 2 35 17 17 30 29 33 14 0...
output:
102081
result:
ok single line: '102081'
Test #5:
score: 0
Accepted
time: 3ms
memory: 3588kb
input:
28 46 6 47 0 12 42 7 43 6 18 32 8 29 9 30 29 43 49 13 41 20 39 49 48 41 20 20 36 26 5 47 32 16 23 13 7 29 42 27 16 48 45 4 9 0 22 35 31 22 27 47 21 34 25 25 2 20 2 25 42 10 38 4 16 4 22 28 28 30 4 19 30 22 28 18 29 28 28 8 32 42 27 4 42 8 20 23 0 37 17 42 35 10 19 26 12 4 14 33 24 15 5 19 22 33 34 4...
output:
566063
result:
ok single line: '566063'
Test #6:
score: 0
Accepted
time: 6ms
memory: 3616kb
input:
50 50 26 38 46 4 41 44 49 42 41 10 12 29 33 22 28 6 43 29 18 43 6 3 11 39 37 25 24 39 33 30 39 47 5 20 37 8 24 23 6 49 40 9 14 4 34 36 0 22 30 35 6 15 32 48 48 10 38 7 2 24 19 18 20 11 26 44 9 40 24 47 23 37 22 24 3 13 33 11 36 38 21 10 40 36 35 46 24 11 23 3 34 20 6 15 12 49 3 25 40 44 5 31 48 38 4...
output:
1522499
result:
ok single line: '1522499'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
1 30 42 47 12 32 43 48 0 33 43 22 12 28 19 16 34 18 34 4 30 13 28 26 6 0 41 32 3 29 23 13
output:
5621
result:
ok single line: '5621'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
36 1 5 29 4 34 9 2 50 5 37 8 14 40 41 7 43 49 39 17 13 4 23 10 38 1 43 36 37 2 13 48 44 44 26 49 1 9
output:
7580
result:
ok single line: '7580'
Test #9:
score: 0
Accepted
time: 10ms
memory: 3828kb
input:
50 50 31 19 20 40 2 22 43 35 22 42 21 1 30 11 41 12 2 31 28 14 32 17 12 41 25 45 21 27 0 4 27 32 23 47 46 26 43 13 35 40 4 6 15 34 42 5 20 18 10 49 6 43 15 19 33 15 13 4 42 38 8 44 19 31 14 40 31 32 2 41 21 6 47 36 14 12 16 35 30 26 7 37 18 47 5 1 11 43 30 28 30 38 21 24 43 35 13 24 16 15 14 11 46 3...
output:
1554666
result:
ok single line: '1554666'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
1 1 15
output:
0
result:
ok single line: '0'
Test #11:
score: 0
Accepted
time: 1ms
memory: 3576kb
input:
22 33 44 6 2 41 43 1 1 24 13 7 12 29 45 5 5 24 37 6 18 31 16 30 18 1 25 48 46 19 45 10 29 12 16 31 2 9 7 28 7 45 35 44 24 4 50 3 2 10 9 46 42 50 25 9 0 0 31 47 19 25 6 48 37 47 3 13 5 10 41 38 29 0 31 2 4 30 5 6 41 40 1 6 39 27 15 14 1 46 35 20 45 41 42 5 11 19 43 17 29 33 4 33 7 9 9 11 40 40 43 4 2...
output:
246865
result:
ok single line: '246865'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3732kb
input:
3 42 5 23 13 38 29 22 41 49 45 42 10 5 5 3 43 21 0 9 24 48 9 37 16 32 43 1 15 36 46 0 14 1 48 2 13 1 24 3 50 43 19 34 49 50 37 15 20 37 24 45 9 7 5 50 14 48 0 29 7 21 3 21 47 1 48 9 27 46 37 26 39 5 34 37 4 21 1 25 32 0 44 41 32 49 41 46 20 15 24 27 36 28 22 32 3 45 41 4 40 1 30 28 7 13 39 36 8 15 3...
output:
36972
result:
ok single line: '36972'
Test #13:
score: 0
Accepted
time: 3ms
memory: 3468kb
input:
29 38 48 21 6 48 5 37 8 12 45 40 7 42 3 44 21 49 19 1 50 18 40 17 35 47 1 22 29 15 32 12 28 30 34 35 1 13 46 9 50 14 24 7 6 1 0 1 50 45 2 49 12 43 41 21 39 16 18 17 31 50 30 33 29 38 17 5 0 38 14 0 1 38 32 32 13 6 33 12 0 36 11 13 28 26 8 16 16 26 7 47 26 37 29 4 24 21 34 50 33 49 24 34 10 5 16 24 1...
output:
445787
result:
ok single line: '445787'
Test #14:
score: 0
Accepted
time: 1ms
memory: 3508kb
input:
14 14 15 36 40 42 15 20 32 38 22 0 18 43 3 38 41 14 12 18 28 32 17 27 27 36 44 29 27 26 33 45 27 22 31 16 38 20 36 19 32 33 44 0 25 48 12 40 36 49 32 13 31 23 15 32 8 8 10 9 34 17 4 11 14 9 1 1 29 12 46 35 45 39 9 44 10 21 33 46 45 39 34 25 12 49 31 20 6 15 30 15 6 34 0 20 43 1 22 46 38 17 4 32 30 1...
output:
36695
result:
ok single line: '36695'
Test #15:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
20 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
output:
0
result:
ok single line: '0'
Test #16:
score: 0
Accepted
time: 1ms
memory: 3520kb
input:
20 20 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
output:
38
result:
ok single line: '38'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
20 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
output:
22
result:
ok single line: '22'