(200724) 코드포스 - Codeforces Round #659 (Div. 2)

Contest link: Codeforces Round #659 - Codeforces

망했군요 :frowning: ㅠㅠ

영혼까지 털렸습니다. 흑흑


Common codes for Codeforces
#include <algorithm>
#include <array>
#include <cmath>
#include <functional> 
#include <iostream>
#include <memory>
#include <queue>
#include <string>
#include <type_traits>
#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; }
};

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);
  }
};

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();

1384A 오답

namespace {
using namespace std;

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

}  // unnamed namespace;

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

  string ans = "", before = "";
  char now = 'a';
  for (int i = 0; i < n; ++i) {
    int input;
    cin >> input;

    ans = "";
    if (i == 0) {
      while (ans.size() < 200) ans += now;

      LOG_INFO << ans;

      before = ans;
      ans = "";
      if(++now > 'z') now = 'a';
    }

    for (int j = 0; j < input; ++j) ans += before[j];
    while (ans.size() < 200) ans += now;

    before = ans;
    if(++now > 'z') now = 'a';

    LOG_INFO << ans;
  }
}

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

  Solver(std::bind(&solve));

  return 0;
}

1384B1 오답

namespace {
using namespace std;

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

INIT_STRING_ANSWER("Yes", "No");
}  // unnamed namespace;

void solve() {
  int n, k, l;
  cin >> n >> k >> l;

  vector<vector<int>> parts;
  vector<int> temp;
  for (int i = 0; i < n; ++i) {
    int input;
    cin >> input;

    if (input > l) {
      LOG_INFO << GET_ANSWER(false);
      return;
    }

    if (input + k <= l) {
      if(temp.size()) parts.emplace_back(std::move(temp));
      temp.clear();  
    } else {
      temp.push_back(input);
    }
  }
  if (temp.size()) parts.emplace_back(std::move(temp));

  for (int pi = 0; pi < parts.size(); ++pi) {
    const auto &part = parts[pi];

    bool success = false;
    for (int i = 0; i < k * 2 && success == false; ++i) {
      int now = i < k ? i : (2 * k - i);
      if(pi == 0 && now > k) break;

      bool flag = i / k;
      for (int j = 0; j < part.size(); ++j) {
        if (part[j] + now > l) {
          break;
        }
        now += flag ? -1 : +1;
        if (now > k) {
          now = k - 1;
          flag = true;
        } else if (now < 0) {
          now = 1;
          flag = false;
        }

        if (j == part.size() - 1) success = true;
      }
    }

    if (success == false) {
      LOG_INFO << GET_ANSWER(false);
      return;
    }
  }

  LOG_INFO << GET_ANSWER(true);
}

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

  Solver(std::bind(&solve));

  return 0;
}

1384A 정답
namespace {
using namespace std;

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

}  // unnamed namespace;

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

  string ans = "", before = "";
  char now = 'a';
  for (int i = 0; i < n; ++i) {
    int input;
    cin >> input;

    ans = "";
    if (i == 0) {
      while (ans.size() < 200) ans += now;

      LOG_INFO << ans;

      before = ans;
      ans = "";
      if(++now > 'z') now = 'a';
    }

    for (int j = 0; j < input; ++j) ans += before[j];
    while (ans.size() < 200) {
      if(now == before[ans.size()]) {
        if(++now > 'z') now = 'a';
      }

      ans += now;
    }

    before = ans;
    if(++now > 'z') now = 'a';

    LOG_INFO << ans;
  }
}

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

  Solver(std::bind(&solve));

  return 0;
}
1384B1 정답
namespace {
using namespace std;

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

INIT_STRING_ANSWER("Yes", "No");
}  // unnamed namespace;

void solve() {
  int n, k, l;
  cin >> n >> k >> l;

  vector<vector<int>> parts;
  vector<int> temp;
  for (int i = 0; i < n; ++i) {
    int input;
    cin >> input;

    if (input > l) {
      LOG_INFO << GET_ANSWER(false);
      while(++i < n) cin >> input;
      return;
    }

    if (input + k <= l) {
      if(temp.size()) parts.emplace_back(std::move(temp));
      temp.clear();  
    } else {
      temp.push_back(input);
    }
  }
  if (temp.size()) parts.emplace_back(std::move(temp));

  for (int pi = 0; pi < parts.size(); ++pi) {
    const auto &part = parts[pi];

    bool success = false;
    for (int i = 0; i < k * 2 && success == false; ++i) {
      int now = i < k ? i : (2 * k - i);
      if(pi == 0 && now > k) break;

      bool flag = i / k;
      for (int j = 0; j < part.size(); ++j) {
        if (part[j] + now > l) {
          break;
        }
        now += flag ? -1 : +1;
        if (now > k) {
          now = k - 1;
          flag = true;
        } else if (now < 0) {
          now = 1;
          flag = false;
        }

        if (j == part.size() - 1) success = true;
      }
    }

    if (success == false) {
      LOG_INFO << GET_ANSWER(false);
      return;
    }
  }

  LOG_INFO << GET_ANSWER(true);
}

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

  Solver(std::bind(&solve));

  return 0;
}

image