(200710) 코드포스

Codeforces materials usage license (v. 0.1) 에 따라 codeforces.com 의 문제임을 알립니다.

Original problem link: Problem - 1370E - Codeforces


Example

Input

6
010000
000001

Output

1

Input

10
1111100000
0000011111

Output

5

Input

8
10101010
01010101

Output

1

Input

10
1111100000
1111100001

Output

-1


Common codes for Codeforces
#include <algorithm>
#include <array>
#include <cmath>
#include <functional> 
#include <iostream>
#include <queue>
#include <string>
#include <unordered_map>
#include <vector>

namespace predefined {

#ifdef CODEFORCES_DEBUG
  constexpr bool kIsDebug = true;
#else
  constexpr bool kIsDebug = false;
#endif

enum class LogType {
  INFO,
  DEBUG
};

template <LogType type, bool... Bools>
struct Log;

template <>
struct Log<LogType::INFO> {
  Log() {}
  ~Log() { std::cout << '\n'; }

  template <typename T>
  Log& operator<< (const T &t) {
    std::cout << t;
    return *this;
  }
};

template <>
struct Log<LogType::DEBUG, true>{
  Log() {}
  ~Log() { std::cout << '\n'; }

  void Open() {
    freopen("input.txt", "r", stdin);
  }

  template <typename T>
  Log& operator<< (const T &t) {
    std::cout << t;
    return *this;
  }
};

template <>
struct Log<LogType::DEBUG, false> {
  Log() {}
  ~Log() {}

  void Open() {}

  template <typename T>
  Log& operator<< (const T &t) { return *this; }
};

template<typename T>
struct BoolMap {
  explicit BoolMap(const T &_true_value, const T &_false_value) 
    : true_value(_true_value),
      false_value(_false_value) {}

  const T true_value;
  const T false_value;

  const T inline GetValue(const bool bool_key) const {
    return bool_key ? true_value : false_value;  
  };
};

}  // predefined;

#define LOG_INFO predefined::Log<predefined::LogType::INFO>()
#define LOG_DEBUG predefined::Log<predefined::LogType::DEBUG, predefined::kIsDebug>()
#define LOG(LEVEL) LOG_##LEVEL
#define LABEL(variable_name) #variable_name << ": " << variable_name << " "

#define INIT_ANSWER(type, true_value, false_value) \
  const predefined::BoolMap<type> predefined_bool_map(true_value, false_value)
#define INIT_STRING_ANSWER(true_string, false_string) \
  INIT_ANSWER(std::string, true_string, false_string)
#define GET_ANSWER(bool_key) \
  predefined_bool_map.GetValue(bool_key)

#define INIT_CODEFORCES() \
  std::ios::sync_with_stdio(false); \
  std::cin.tie(NULL); \
  LOG(DEBUG).Open(); \

이러다 정말 몸도 마음도 근육맨 되시겠네요, 홧팅!

1 Like

RPG 중 입니다. ㅋㅋ

predefined에 solver struct 를 추가하였습니다.

문제가 multi TC랑 single TC 인 문제가 있는데요.
Debug 모드에서는 항상 multi TC 인게 편해서요.

Debug 일때는 항상 multi TC, Debug도 아니고 Multi TC 문제도 아니면 single TC로 작동합니다.


namespace solver {
  
using SolveFunc = std::function<void()>;

template<typename MultiRunner>
void Run(SolveFunc solve_func);

template<>
void Run<std::true_type>(SolveFunc solve_func) {
  int test_case;
  std::cin >> test_case;

  while (test_case--) {
    solve_func();
  }
}

template<>
void Run<std::false_type>(SolveFunc solve_func) {
  solve_func();
}

} // solver

template <bool MultiTest>
struct Solver {
  constexpr static bool condition = MultiTest | kIsDebug;
  typedef typename std::conditional<condition, std::true_type, std::false_type>::type run_type;

  explicit Solver(solver::SolveFunc solve_func) {
    solver::Run<run_type>(solve_func);
  }
};

main logic은 이렇게 변경하였습니다.

namespace {
using namespace std;

constexpr bool kMultiTestCase = false;
using Solver = predefined::Solver<kMultiTestCase>;

}  // unnamed namespace;

void solve() {
  LOG_DEBUG << "Solver test";
}

int main(int argc, char** argv) {
  INIT_CODEFORCES();

  Solver(std::bind(solve));

  return 0;
}

1370E
namespace {
using namespace std;

constexpr bool kMultiTestCase = false;
using Solver = predefined::Solver<kMultiTestCase>;

}  // unnamed namespace;

void solve() {
  int n;
  string s, t;
  cin >> n >> s >> t;

  int s_count = 0, t_count = 0;
  int zero_first = 0, one_first = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] == '0') ++s_count;
    if (t[i] == '0') ++t_count;

    if (s[i] != t[i]) {
      if (s[i] == '0') {
        ++zero_first;
        one_first -= (one_first != 0);
      } else {
        ++one_first;
        zero_first -= (zero_first != 0);
      } 
    }
  }

  if (s_count != t_count) {
    LOG_INFO << -1; 
    return ;
  }

  LOG_INFO << zero_first + one_first;
}

int main(int argc, char** argv) {
  INIT_CODEFORCES();

  Solver(std::bind(solve));

  return 0;
}