結果

問題 No.1246 ANDORゲーム(max)
ユーザー milanis48663220milanis48663220
提出日時 2021-05-12 01:11:23
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,141 bytes
コンパイル時間 1,436 ms
コンパイル使用メモリ 129,640 KB
実行使用メモリ 18,556 KB
最終ジャッジ日時 2023-10-22 06:18:39
合計ジャッジ時間 6,620 ms
ジャッジサーバーID
(参考情報)
judge12 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
4,348 KB
testcase_09 WA -
testcase_10 AC 2 ms
4,348 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 37 ms
18,552 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 100 ms
18,552 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;
using T = tuple<int, int, bool>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, t; cin >> n >> t;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    ll ans = 0;
    vector<vector<int>> r(n, vector<int>(30, -1));
    for(int i = 0; i < 30; i++){
        int f = t&(1<<i);
        int l = -1;
        for(int j = 0; j < n; j++){
            int g = a[j]&(1<<i);
            if(f != g){
                if(l != -1) r[l][i] = j-1;
                l = j;
                f = g;
            }
        }
        if(l != -1) r[l][i] = n-1;
    }
    // for(int i = 0; i < n; i++) {
    //     cout << i << ' ';
    //     for(int j = 0; j < 30; j++){
    //         if(r[i][j] != -1) cout << j << ':' << r[i][j] << ' ';
    //     }
    //     cout << endl;
    // }
    priority_queue<T, vector<T>, greater<T>> que;
    int cur = t;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 30; j++){
            if(r[i][j] != -1) {
                bool ope_and = (a[i]&(1<<j)) == 0;
                que.push(T(r[i][j], -j, ope_and));
            }
        }
        while(!que.empty()){
            auto [r, j, ope_and] = que.top(); que.pop();
            if(r < i) continue;
            j = -j;
            int nx = ope_and ? (cur&a[r]) : (cur|a[r]);
            if(cur != nx){
                ans += abs(nx-cur);
                cur = nx;
                break;
            }
        }
    }
    cout << ans << endl;
}
0