結果
| 問題 | No.1780 [Cherry Anniversary] 真冬に咲く26の櫻の木 |
| コンテスト | |
| ユーザー |
emthrm
|
| 提出日時 | 2021-12-09 00:43:43 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 201 ms / 2,000 ms |
| コード長 | 2,443 bytes |
| コンパイル時間 | 1,824 ms |
| コンパイル使用メモリ | 199,444 KB |
| 最終ジャッジ日時 | 2025-01-26 07:03:00 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 42 |
ソースコード
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int DY[]{1, 0, -1, 0}, DX[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1}, DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
IOSetup() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << fixed << setprecision(20);
}
} iosetup;
int main() {
constexpr int CHERRY = 26, C = 16, B = 24;
int c[CHERRY]{}, k[CHERRY]{};
REP(i, CHERRY) cin >> c[i], --c[i];
REP(i, CHERRY) cin >> k[i];
int n; cin >> n;
vector<string> s(n);
vector<int> a(n), b(n), e(n);
REP(i, n) cin >> s[i] >> a[i] >> b[i] >> e[i], --a[i], --b[i];
ll ans[C]{};
REP(cherry, CHERRY) {
ll dp1[B][C][C]{};
REP(bit, B) REP(i, C) {
fill(dp1[bit][i], dp1[bit][i] + C, -LINF);
dp1[bit][i][i] = 0;
}
REP(i, n) {
if (count(ALL(s[i]), 'A' + cherry) > 0) {
chmax(dp1[0][a[i]][b[i]], e[i]);
chmax(dp1[0][b[i]][a[i]], e[i]);
}
}
REP(bit, B - 1) REP(i, C) REP(j, C) {
REP(k, C) {
if (dp1[bit][i][k] != -LINF && dp1[bit][k][j] != -LINF) {
chmax(dp1[bit + 1][i][j], dp1[bit][i][k] + dp1[bit][k][j]);
}
}
}
ll dp2[C]{};
fill(dp2, dp2 + C, -LINF);
dp2[c[cherry]] = 0;
REP(bit, B) {
if (k[cherry] >> bit & 1) {
ll nxt[C]{};
fill(nxt, nxt + C, -LINF);
REP(i, C) {
if (dp2[i] == -LINF) continue;
REP(j, C) {
if (dp1[bit][i][j] != -LINF) chmax(nxt[j], dp2[i] + dp1[bit][i][j]);
}
}
swap(dp2, nxt);
}
}
REP(i, C) {
if (dp2[i] == -LINF) {
ans[i] = -LINF;
} else if (ans[i] != -LINF) {
ans[i] += dp2[i];
}
}
}
const ll energy = *max_element(ans, ans + C);
if (energy == -LINF) {
cout << "Impossible\n";
} else {
cout << energy << '\n';
}
return 0;
}
emthrm