結果
問題 |
No.437 cwwゲーム
|
ユーザー |
![]() |
提出日時 | 2025-08-24 12:06:20 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 1,222 bytes |
コンパイル時間 | 1,178 ms |
コンパイル使用メモリ | 162,716 KB |
実行使用メモリ | 7,720 KB |
最終ジャッジ日時 | 2025-08-24 12:06:24 |
合計ジャッジ時間 | 2,697 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 |
ソースコード
# include <bits/stdc++.h> # define int long long # define FILE(x) freopen(x ".in", "r", stdin); freopen(x ".out", "w", stdout); using namespace std; int n; string s; int a[100]; int f[10005]; int ans; void solve() { cin >> s; n = s.size(); for (int i = 0; i < n; i ++) { a[i] = s[i] - '0'; } fill(f + 1, f + 1 + n, -1e18); for (int s = 0; s < (1 << n); s ++) { if (f[s] == -1e18) continue; for (int i = 0; i < n; i ++) { if (!a[i]) continue; for (int j = i + 1; j < n; j ++) { for (int k = j + 1; k < n; k ++) { if (a[j] != a[k]) continue; if (a[i] == a[j]) continue; if ((s & ((1 << i) | (1 << j) | (1 << k))) == 0) { int ns = s | (1 << i) | (1 << j) | (1 << k); f[ns] = max(f[ns], f[s] + a[i] * 100 + a[j] * 11); } } } } } cout << *max_element(f, f + (1 << n)); } signed main() { ios :: sync_with_stdio(0); cin.tie(0), cout.tie(0); int T = 1; while (T --) solve(); return 0; }