結果

問題 No.1493 隣接xor
ユーザー zhou-jkzhou-jk
提出日時 2021-07-11 12:12:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 683 bytes
コンパイル時間 698 ms
コンパイル使用メモリ 77,668 KB
実行使用メモリ 10,772 KB
最終ジャッジ日時 2023-09-14 20:08:12
合計ジャッジ時間 7,767 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<unordered_map>
using namespace std;
const int N=200005;
const int MOD=1000000007;
int n;
int a[N];
int sum[N];
int f[N];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)
        sum[i]=sum[i-1]^a[i];
    unordered_map<int,int>pre;
    f[0]=1;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<i;j++)
            f[i]=(f[i]+f[j])%MOD;
        if(pre[sum[i]]) f[i]=(f[i]-f[pre[sum[i]]])%MOD;
        pre[sum[i]]=i;
    }
    int ans=0;
    for(int i=1;i<=n;i++)
        if((sum[i]^sum[n])==0) ans=(ans+f[i])%MOD;
    ans=(ans+MOD)%MOD;
    printf("%d",ans);
    return 0;
}
0