結果

問題 No.1183 コイン遊び
ユーザー Haar
提出日時 2020-08-22 13:06:00
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 249 ms / 2,000 ms
コード長 952 bytes
コンパイル時間 2,455 ms
コンパイル使用メモリ 198,016 KB
最終ジャッジ日時 2025-01-13 07:07:52
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

/**
 * @title Run length encoding
 * @docs run_length_encoding.md
 */
template <typename Container, typename T = typename Container::value_type>
auto run_length_encoding(const Container &v){
  std::vector<std::pair<T,int64_t>> ret;

  for(auto &x : v){
    if(ret.empty()) ret.emplace_back(x, 1);
    else if(ret.back().first == x) ++ret.back().second;
    else ret.emplace_back(x, 1);
  }

  return ret;
}


namespace solver{
  void solve(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);

    int N; std::cin >> N;
    std::vector<int> A(N), B(N);
    for(int i = 0; i < N; ++i) std::cin >> A[i];
    for(int i = 0; i < N; ++i) std::cin >> B[i];

    for(int i = 0; i < N; ++i){
      A[i] = A[i] ^ B[i];
    }

    auto r = run_length_encoding(A);

    int ans = 0;

    for(auto [x, i] : r){
      if(x == 1) ++ans;
    }

    
    std::cout << ans << "\n";
  }
}

int main(){
  solver::solve();
  return 0;
}
0