結果

問題 No.1183 コイン遊び
ユーザー MisterMister
提出日時 2020-08-22 13:40:18
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 921 bytes
コンパイル時間 772 ms
コンパイル使用メモリ 79,528 KB
実行使用メモリ 15,804 KB
最終ジャッジ日時 2024-04-23 08:06:50
合計ジャッジ時間 4,981 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 4 ms
6,940 KB
testcase_11 AC 10 ms
6,944 KB
testcase_12 AC 79 ms
10,344 KB
testcase_13 AC 73 ms
9,700 KB
testcase_14 AC 118 ms
11,696 KB
testcase_15 AC 124 ms
11,688 KB
testcase_16 AC 128 ms
12,332 KB
testcase_17 AC 128 ms
11,952 KB
testcase_18 AC 125 ms
12,844 KB
testcase_19 AC 124 ms
12,716 KB
testcase_20 AC 130 ms
13,232 KB
testcase_21 AC 107 ms
7,212 KB
testcase_22 AC 101 ms
7,116 KB
testcase_23 AC 104 ms
7,212 KB
testcase_24 AC 104 ms
7,248 KB
testcase_25 AC 125 ms
11,948 KB
testcase_26 AC 125 ms
12,844 KB
testcase_27 AC 138 ms
11,820 KB
testcase_28 AC 135 ms
11,696 KB
testcase_29 AC 107 ms
7,204 KB
testcase_30 AC 114 ms
15,804 KB
testcase_31 AC 124 ms
11,688 KB
testcase_32 AC 125 ms
11,948 KB
testcase_33 AC 124 ms
11,824 KB
testcase_34 AC 125 ms
11,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>

template <class It>
std::vector<std::pair<typename It::value_type, int>> runlength(
    It begin, It end) {
    using T = typename It::value_type;

    std::vector<std::pair<T, int>> res;
    while (begin != end) {
        const T& c = *(begin++);
        if (res.empty() || c != res.back().first) {
            res.emplace_back(c, 1);
        } else {
            ++res.back().second;
        }
    }

    return res;
}

void solve() {
    int n;
    std::cin >> n;

    std::vector<int> xs(n);
    for (auto& x : xs) std::cin >> x;
    for (auto& x : xs) {
        int y;
        std::cin >> y;
        x ^= y;
    }

    auto ps = runlength(xs.begin(), xs.end());

    int ans = 0;
    for (auto [c, l] : ps) ans += c;
    std::cout << ans << "\n";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0