結果

問題 No.2672 Subset Xor Sum
ユーザー tour2sttour2st
提出日時 2024-03-15 21:49:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 245 ms / 2,000 ms
コード長 2,024 bytes
コンパイル時間 767 ms
コンパイル使用メモリ 95,852 KB
実行使用メモリ 325,732 KB
最終ジャッジ日時 2024-03-16 17:40:58
合計ジャッジ時間 6,292 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,892 KB
testcase_01 AC 3 ms
9,764 KB
testcase_02 AC 4 ms
10,148 KB
testcase_03 AC 3 ms
10,020 KB
testcase_04 AC 3 ms
10,020 KB
testcase_05 AC 3 ms
10,148 KB
testcase_06 AC 4 ms
10,148 KB
testcase_07 AC 4 ms
10,020 KB
testcase_08 AC 3 ms
10,020 KB
testcase_09 AC 4 ms
10,020 KB
testcase_10 AC 4 ms
10,148 KB
testcase_11 AC 4 ms
10,148 KB
testcase_12 AC 4 ms
10,020 KB
testcase_13 AC 4 ms
10,020 KB
testcase_14 AC 4 ms
10,020 KB
testcase_15 AC 3 ms
10,020 KB
testcase_16 AC 3 ms
10,020 KB
testcase_17 AC 3 ms
10,020 KB
testcase_18 AC 4 ms
10,020 KB
testcase_19 AC 4 ms
10,020 KB
testcase_20 AC 4 ms
10,020 KB
testcase_21 AC 4 ms
10,020 KB
testcase_22 AC 3 ms
10,148 KB
testcase_23 AC 3 ms
10,148 KB
testcase_24 AC 4 ms
10,020 KB
testcase_25 AC 4 ms
10,020 KB
testcase_26 AC 9 ms
20,580 KB
testcase_27 AC 9 ms
20,580 KB
testcase_28 AC 3 ms
10,148 KB
testcase_29 AC 3 ms
10,148 KB
testcase_30 AC 3 ms
10,020 KB
testcase_31 AC 110 ms
6,676 KB
testcase_32 AC 45 ms
6,676 KB
testcase_33 AC 39 ms
6,676 KB
testcase_34 AC 78 ms
6,676 KB
testcase_35 AC 108 ms
6,676 KB
testcase_36 AC 90 ms
6,676 KB
testcase_37 AC 103 ms
6,676 KB
testcase_38 AC 53 ms
6,676 KB
testcase_39 AC 119 ms
6,676 KB
testcase_40 AC 22 ms
6,676 KB
testcase_41 AC 69 ms
6,676 KB
testcase_42 AC 104 ms
6,676 KB
testcase_43 AC 82 ms
6,676 KB
testcase_44 AC 123 ms
6,676 KB
testcase_45 AC 78 ms
6,676 KB
testcase_46 AC 3 ms
6,676 KB
testcase_47 AC 245 ms
325,604 KB
testcase_48 AC 3 ms
6,676 KB
testcase_49 AC 3 ms
6,676 KB
testcase_50 AC 3 ms
6,676 KB
testcase_51 AC 209 ms
325,732 KB
testcase_52 AC 209 ms
325,732 KB
testcase_53 AC 205 ms
325,604 KB
testcase_54 AC 207 ms
325,604 KB
testcase_55 AC 217 ms
325,604 KB
testcase_56 AC 3 ms
6,676 KB
testcase_57 AC 126 ms
228,196 KB
testcase_58 AC 43 ms
86,116 KB
testcase_59 AC 2 ms
6,676 KB
testcase_60 AC 3 ms
6,676 KB
testcase_61 AC 3 ms
6,676 KB
testcase_62 AC 91 ms
147,556 KB
testcase_63 AC 110 ms
176,228 KB
testcase_64 AC 170 ms
269,796 KB
testcase_65 AC 54 ms
86,116 KB
testcase_66 AC 3 ms
9,764 KB
testcase_67 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <random>
#include <time.h>
#include <map>
using namespace std;

int n,a[500000],sum;
//dp[flag][i][j] = 
//i個目まで見てxorがjであるようなとき
//aの要素の使用個数の最小値
//flag:1つ以上使ったか?
int dp[2][5010][1<<13];

int main()
{
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        sum ^= a[i];
    }

    //すべてのxorが0出ないなら存在しない
    if(sum != 0)
    {
        cout << "No" << endl;
    }
    else
    {
        //5001個より多いなら鳩ノ巣原理より、一致するものが存在
        //よってYes
        if(n>5001)
        {
            cout << "Yes" << endl;
        }
        else
        {
            for(int i = 0; i <= n; i++)
            {
                for(int j = 0; j < (1<<13); j++)
                {
                    dp[0][i][j] = dp[1][i][j] = 100000;
                }
            }
            dp[0][0][0] = 0;
            for(int i = 0; i < n; i++)
            {
                for(int j = 0; j < (1<<13); j++)
                {
                    if(dp[0][i][j]<100000)
                    {
                        //printf("[%d:%d]%d->%d\n",i,j,j,j^a[i]);
                        dp[0][i+1][j] = min(dp[0][i+1][j],dp[0][i][j]);
                        dp[1][i+1][j^a[i]] = min(dp[1][i+1][j^a[i]],dp[0][i][j]+1);
                    }
                    if(dp[1][i][j]<100000)
                    {
                        dp[1][i+1][j] = min(dp[1][i+1][j],dp[1][i][j]);
                        dp[1][i+1][j^a[i]] = min(dp[1][i+1][j^a[i]],dp[1][i][j]+1);
                    }
                }
            }
            if(dp[1][n][0]<n)
            {
                //cout << dp[1][n][0] << endl;
                cout << "Yes" << endl;
            }
            else
            {
                cout << "No" << endl;
            }
        }
    }
}
0