Submission #75182


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <bits/extc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector c(n, vector(m, int()));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> c[i][j];
}
}
long long res = -1;
for (int i = 0; i < m; ++i) {
vector dp(n + 1, vector(m, -1LL));
dp[0][i] = c[0][i];
for (int j = 1; j < n; ++j) {
for (int k = 0; k < m; ++k) {
for (int l = 0; l < m; ++l) {
if (gcd(c[j][k], c[j - 1][l]) == 1) {
dp[j][k] = max(dp[j][k], dp[j - 1][l] + c[j][k]);
}
}
}
}
for (int j = 0; j < m; ++j) {
if (gcd(c[0][i], c[n - 1][j]) == 1) {
res = max(res, dp[n - 1][j]);
}
}
}
cout << res << '\n';
return (0);
}

ステータス

項目 データ
問題 1658 - Relatively Prime
ユーザー名 syoribu
投稿日時 2023-08-24 08:11:31
言語 C++17
状態 Accepted
得点 100
ソースコード長 954 Byte
最大実行時間 1761 ms
最大メモリ使用量 700 KB

セット

セット 得点 Cases
1 ALL 100 / 100 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
corner_input01.txt AC 1611 ms 604 KB
1
corner_input02.txt AC 1594 ms 384 KB
1
corner_input03.txt AC 1622 ms 420 KB
1
corner_input04.txt AC 1576 ms 452 KB
1
corner_input05.txt AC 1622 ms 484 KB
1
corner_input06.txt AC 1733 ms 644 KB
1
corner_input07.txt AC 1716 ms 544 KB
1
corner_input08.txt AC 1761 ms 580 KB
1
corner_input09.txt AC 1730 ms 616 KB
1
corner_input10.txt AC 1748 ms 652 KB
1
corner_input11.txt AC 26 ms 552 KB
1
corner_input12.txt AC 24 ms 524 KB
1
corner_input13.txt AC 18 ms 500 KB
1
corner_input14.txt AC 31 ms 600 KB
1
corner_input15.txt AC 21 ms 564 KB
1
random_input01.txt AC 24 ms 536 KB
1
random_input02.txt AC 23 ms 632 KB
1
random_input03.txt AC 24 ms 600 KB
1
random_input04.txt AC 25 ms 572 KB
1
random_input05.txt AC 18 ms 664 KB
1
random_input06.txt AC 47 ms 636 KB
1
random_input07.txt AC 44 ms 468 KB
1
random_input08.txt AC 26 ms 560 KB
1
random_input09.txt AC 61 ms 652 KB
1
random_input10.txt AC 31 ms 608 KB
1
random_input11.txt AC 1261 ms 700 KB
1
random_input12.txt AC 350 ms 612 KB
1
random_input13.txt AC 780 ms 552 KB
1
random_input14.txt AC 593 ms 600 KB
1
random_input15.txt AC 368 ms 652 KB
1
random_input16.txt AC 1745 ms 576 KB
1
random_input17.txt AC 1733 ms 612 KB
1
random_input18.txt AC 1752 ms 644 KB
1
random_input19.txt AC 1731 ms 676 KB
1
random_input20.txt AC 1749 ms 580 KB
1
sample_input01.txt AC 24 ms 616 KB
1
sample_input02.txt AC 19 ms 588 KB
1
sample_input03.txt AC 24 ms 688 KB
1
sample_input04.txt AC 21 ms 656 KB
1
sample_input05.txt AC 21 ms 624 KB
1