Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
32782 | 林芳菲 | 【J】序列 | C++ | 运行超时 | 48 | 1000 MS | 328 KB | 1116 | 2024-09-30 20:31:17 |
#include <cstdio> #include <iostream> #include <algorithm> using namespace std; int n, cnt; int f[130][130]; int t[130], len[130]; int a[130], c[130]; long long ans; int lcm(int x, int y) { return x / __gcd(x, y) * y; } long long cal(int l, int r) { long long s = 0; for (int i = l; i <= r; i++) s += f[i][r] - f[i][l - 1]; return s; } int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) cin >> c[i]; for (int i = 1; i <= n; i++) for (int j = 1; j <= c[i]; j++) len[++cnt] = i; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) f[i][j] = f[i][j - 1] + lcm(a[i], a[j]); for (int i = 1; i <= cnt; i++) t[i] = i; do { int b = 1; long long s = 0; for (int i = 1; i <= cnt; i++) { s += cal(b, b + len[t[i]] - 1); b += len[t[i]]; } ans = max(ans, s); } while (next_permutation(t + 1, t + cnt + 1)); cout << ans << endl; return 0; }