結果

問題 No.1493 隣接xor
ユーザー KKT89KKT89
提出日時 2021-12-06 22:26:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 144 ms / 2,000 ms
コード長 1,377 bytes
コンパイル時間 1,757 ms
コンパイル使用メモリ 140,876 KB
実行使用メモリ 15,120 KB
最終ジャッジ日時 2023-09-21 15:55:10
合計ジャッジ時間 6,220 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 144 ms
15,008 KB
testcase_04 AC 140 ms
14,568 KB
testcase_05 AC 138 ms
14,644 KB
testcase_06 AC 139 ms
14,972 KB
testcase_07 AC 143 ms
15,004 KB
testcase_08 AC 141 ms
15,120 KB
testcase_09 AC 136 ms
14,568 KB
testcase_10 AC 137 ms
14,716 KB
testcase_11 AC 144 ms
14,592 KB
testcase_12 AC 141 ms
15,116 KB
testcase_13 AC 28 ms
5,352 KB
testcase_14 AC 15 ms
5,300 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 62 ms
8,996 KB
testcase_21 AC 72 ms
9,784 KB
testcase_22 AC 48 ms
7,700 KB
testcase_23 AC 65 ms
9,044 KB
testcase_24 AC 133 ms
14,332 KB
testcase_25 AC 48 ms
7,704 KB
testcase_26 AC 78 ms
10,436 KB
testcase_27 AC 30 ms
6,208 KB
testcase_28 AC 119 ms
13,600 KB
testcase_29 AC 81 ms
10,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <sstream>
#include <utility>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <array>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

constexpr ll mod = 1e9+7;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n),b(n+1);
    for(int i=0;i<n;i++){
        cin >> a[i];
        b[i+1] = a[i] ^ b[i];
    }
    vector<int> dp(n);
    dp[0] = 1;
    map<int,int> last;
    for(int i=1;i<n;i++){
        dp[i] = dp[i-1] * 2 % mod;
        if(last.find(b[i]) != last.end()){
            dp[i] -= dp[last[b[i]]-1];
            if(dp[i] < 0){
                dp[i] += mod;
            }
        }
        last[b[i]] = i;
    }
    cout << dp.back() << endl;
}
0