結果

問題 No.183 たのしい排他的論理和(EASY)
ユーザー @abcde@abcde
提出日時 2019-04-29 09:09:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 21 ms / 5,000 ms
コード長 1,382 bytes
コンパイル時間 1,274 ms
コンパイル使用メモリ 155,224 KB
実行使用メモリ 6,408 KB
最終ジャッジ日時 2023-09-14 16:10:39
合計ジャッジ時間 2,357 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 6 ms
4,380 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 8 ms
4,816 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 21 ms
6,380 KB
testcase_08 AC 10 ms
4,876 KB
testcase_09 AC 10 ms
4,872 KB
testcase_10 AC 10 ms
4,932 KB
testcase_11 AC 11 ms
4,948 KB
testcase_12 AC 17 ms
6,408 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 11 ms
4,948 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 10 ms
4,816 KB
testcase_18 AC 20 ms
6,368 KB
testcase_19 AC 9 ms
5,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 以下の問題を参考に対応.
// No.4 おもりと天秤
// https://yukicoder.me/problems/no/4
#include <bits/stdc++.h>
using namespace std;

// 作成可能な整数のリストを更新する.
// @param m: 整数のリスト.
// @param n: 追加する整数.
// @return ret: 更新した作成可能な整数のリスト.
map<int, int> updateIntegers(map<int, int> m, int n){
    map<int, int> ret;
    for(auto &p : m) ret[p.first]++, ret[(p.first ^ n)]++;
    // for(auto &p : ret) cout << "updateIntegers(ret): " << p.first << " ";
    // cout << endl;
    return ret;
}

int main() {
    
    // 1. 入力情報取得.
    int N;
    cin >> N;
    
    // 2. 入力データから作成可能な整数のリストを更新していく.
    int A[N];
    cin >> A[0];
    map<int, int> ans;
    ans[0]++, ans[A[0]]++;
    for(int i = 1; i < N; i++){
        cin >> A[i];
        if(ans[A[i]] == 0){
            map<int, int> lm = updateIntegers(ans, A[i]);
            swap(ans, lm);
        }
    }
    // for(auto &p : ans) cout << p.first << " ";
    // cout << endl;
    
    // 3. 出力 ~ 後処理.
    // ex.
    // 5
    // 1 7 101 212 333
    // -> 32 で OK ???.
    // 0 1 6 7 98 99 100 101 176 177 182 183 210 211 212 
    // 213 296 297 302 303 330 331 332 333 408 409 414 415 506 507 
    // 508 509
    cout << ans.size() << endl;
    return 0;
    
}
0