Submission #75184


ソースコード

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <bits/extc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
assert(1 <= n && n <= 100);
assert(1 <= m && m <= 50);
vector c(n, vector(m, int()));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> c[i][j];
assert(1 <= c[i][j] && c[i][j] <= 1000000000);
}
}
vector tbl(n, vector(m, vector(m, false)));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
for (int k = 0; k < m; ++k) {
tbl[i][j][k] = gcd(c[i][j], c[(i + 1) % n][k]) == 1;
}
}
}
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 (tbl[j - 1][l][k]) {
dp[j][k] = max(dp[j][k], dp[j - 1][l] + c[j][k]);
}
}
}
}
for (int j = 0; j < m; ++j) {
if (tbl[n - 1][j][i]) {
res = max(res, dp[n - 1][j]);
}
}
}
cout << res << '\n';
return (0);
}

ステータス

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

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
corner_input01.txt AC 65 ms 988 KB
1
corner_input02.txt AC 64 ms 1044 KB
1
corner_input03.txt AC 61 ms 848 KB
1
corner_input04.txt AC 61 ms 904 KB
1
corner_input05.txt AC 62 ms 964 KB
1
corner_input06.txt AC 75 ms 900 KB
1
corner_input07.txt AC 78 ms 960 KB
1
corner_input08.txt AC 78 ms 1012 KB
1
corner_input09.txt AC 80 ms 944 KB
1
corner_input10.txt AC 79 ms 1000 KB
1
corner_input11.txt AC 22 ms 544 KB
1
corner_input12.txt AC 24 ms 508 KB
1
corner_input13.txt AC 28 ms 608 KB
1
corner_input14.txt AC 31 ms 444 KB
1
corner_input15.txt AC 20 ms 408 KB
1
random_input01.txt AC 29 ms 628 KB
1
random_input02.txt AC 24 ms 596 KB
1
random_input03.txt AC 18 ms 560 KB
1
random_input04.txt AC 16 ms 656 KB
1
random_input05.txt AC 31 ms 624 KB
1
random_input06.txt AC 46 ms 464 KB
1
random_input07.txt AC 22 ms 520 KB
1
random_input08.txt AC 25 ms 580 KB
1
random_input09.txt AC 23 ms 640 KB
1
random_input10.txt AC 21 ms 540 KB
1
random_input11.txt AC 84 ms 844 KB
1
random_input12.txt AC 35 ms 736 KB
1
random_input13.txt AC 58 ms 768 KB
1
random_input14.txt AC 56 ms 712 KB
1
random_input15.txt AC 46 ms 804 KB
1
random_input16.txt AC 90 ms 1040 KB
1
random_input17.txt AC 91 ms 968 KB
1
random_input18.txt AC 90 ms 1028 KB
1
random_input19.txt AC 88 ms 1084 KB
1
random_input20.txt AC 95 ms 1144 KB
1
sample_input01.txt AC 27 ms 568 KB
1
sample_input02.txt AC 22 ms 792 KB
1
sample_input03.txt AC 24 ms 760 KB
1
sample_input04.txt AC 27 ms 588 KB
1
sample_input05.txt AC 18 ms 680 KB
1