結果
問題 |
No.1246 ANDORゲーム(max)
|
ユーザー |
|
提出日時 | 2021-05-01 02:18:02 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 442 ms / 2,000 ms |
コード長 | 823 bytes |
コンパイル時間 | 976 ms |
コンパイル使用メモリ | 91,484 KB |
最終ジャッジ日時 | 2025-01-21 04:58:20 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
ソースコード
#include <iostream> #include <cmath> #include <map> using namespace std; using lint = long long; void solve() { int n, t; cin >> n >> t; map<lint, lint> dp{{t, 0}}; while (n--) { lint x; cin >> x; map<lint, lint> ndp; for (auto [t, c] : dp) { { auto nt = t & x; auto nc = c + abs(t - nt); ndp[nt] = max(ndp[nt], nc); } { auto nt = t | x; auto nc = c + abs(t - nt); ndp[nt] = max(ndp[nt], nc); } } swap(dp, ndp); } lint ans = 0; for (auto [t, c] : dp) ans = max(ans, c); cout << ans << "\n"; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }