結果

問題 No.1377 Half xor Half
ユーザー risujirohrisujiroh
提出日時 2021-02-05 23:52:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 2,819 bytes
コンパイル時間 3,740 ms
コンパイル使用メモリ 203,772 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-15 11:00:29
合計ジャッジ時間 6,296 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 2 ms
4,384 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 3 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 2 ms
4,384 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#pragma region my_template

struct Rep {
  struct I {
    int i;
    void operator++() { ++i; }
    int operator*() const { return i; }
    bool operator!=(I o) const { return i < *o; }
  };
  const int l_, r_;
  Rep(int l, int r) : l_(l), r_(r) {}
  Rep(int n) : Rep(0, n) {}
  I begin() const { return {l_}; }
  I end() const { return {r_}; }
};
struct Per {
  struct I {
    int i;
    void operator++() { --i; }
    int operator*() const { return i; }
    bool operator!=(I o) const { return i > *o; }
  };
  const int l_, r_;
  Per(int l, int r) : l_(l), r_(r) {}
  Per(int n) : Per(0, n) {}
  I begin() const { return {r_ - 1}; }
  I end() const { return {l_ - 1}; }
};

template <class F>
struct Fix : private F {
  Fix(F f) : F(f) {}
  template <class... Args>
  decltype(auto) operator()(Args&&... args) const {
    return F::operator()(*this, std::forward<Args>(args)...);
  }
};

template <class T = int>
T scan() {
  T res;
  std::cin >> res;
  return res;
}

template <class T, class U = T>
bool chmin(T& a, U&& b) {
  return b < a ? a = std::forward<U>(b), true : false;
}
template <class T, class U = T>
bool chmax(T& a, U&& b) {
  return a < b ? a = std::forward<U>(b), true : false;
}

#ifndef LOCAL
#define DUMP(...) void(0)
template <int OnlineJudge, int Local>
constexpr int OjLocal = OnlineJudge;
#endif

using namespace std;

#define ALL(c) begin(c), end(c)

#pragma endregion

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int n = scan();
  auto s = scan<string>();
  auto t = scan<string>();
  vector<int> a(n), b(n);
  for (int i : Rep(n)) {
    a[i] = 2 * (s[i] & 1) + (s[n + i] & 1);
    b[i] = 2 * (t[i] & 1) + (t[n + i] & 1);
    if ((a[i] == 0) ^ (b[i] == 0)) {
      cout << "-1\n";
      exit(0);
    }
  }

  vector<int> ans;
  auto go = [&](int x) {
    ans.push_back(x);
    if (0 <= x and x < n) {
      for (int i : Rep(n))
        if (i < x and a[i] & 2)
          a[i] ^= 1;
        else if (i >= x and a[i] & 1)
          a[i] ^= 2;
    } else if (n <= x and x < 2 * n) {
      x -= n;
      for (int i : Rep(n))
        if (i < x and a[i] & 1)
          a[i] ^= 2;
        else if (i >= x and a[i] & 2)
          a[i] ^= 1;
    } else
      assert(false);
  };

  for (int i : Rep(n)) {
    if (a[i] == 1 and b[i] == 2) go(0), go(n + i);
    if (a[i] == 2 and b[i] == 1) go(n), go(i);
    if (a[i] == 1 and b[i] == 3) go(n + i), go(0);
    if (a[i] == 3 and b[i] == 1) go(0), go(n + i);
    if (a[i] == 2 and b[i] == 3) go(i), go(n);
    if (a[i] == 3 and b[i] == 2) go(n), go(i);
    assert(a[i] == b[i]);
  }

  cout << size(ans) << '\n';
  for (auto&& e : ans) cout << e << '\n';
}
0