(200729) 코드포스 - Educational Codeforces Round 92 (Rated for Div. 2)

FTF

Contest link: Educational Codeforces Round 92 (Rated for Div. 2) - Codeforces

1389A
namespace {
using namespace std;

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

}  // unnamed namespace;

int Gcd(int a, int b) {
  while(a && b) a > b ? a %= b : b %= a;
  return a | b;
}

void solve() {
  int a, b;
  cin >> a >> b;
  
  if (b < a * 2) LOG_INFO << "-1 -1";
  else LOG_INFO << a << ' ' << a * 2;
}

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

  Solver([](){solve();});

  return 0;
}
1389B 오답
namespace {
using namespace std;

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

}  // unnamed namespace;

void solve() {
  int n, k, z;

  cin >> n >> k >> z;

  vector<int64_t> inputs(n);
  vector<pair<int64_t,int>> sums(n-1);
  int64_t total = 0;

  cin >> inputs[0];
  total += inputs[0];
  for (int i = 1 ; i < n; ++i) {
    cin >> inputs[i];
    sums[i - 1].first = inputs[i - 1] + inputs[i];
    sums[i - 1].second = i - 1;
    if (i <= k) total += inputs[i];
  }

  sort(sums.begin(), sums.end(), [](const pair<int64_t,int> &a, const pair<int64_t,int> &b)->bool{
    if (a.first > b.first) return true;
    else if (a.first == b.first) return a.second < b.second;
    else return false;
  });

  // int now, int last, int check
  int64_t ans = 0;

  auto dfs = make_shared<unique_ptr<function<void(int, int, int )>>>();
  *dfs = make_unique<function<void(int, int, int)>>(
    [&](int now, int last, int count) {
      ans = max(ans, total);
      int advanced_boundary = k - 2 * count;

      if (now == advanced_boundary && count < z  && last != advanced_boundary) {
        total -= inputs[advanced_boundary];
        total += inputs[advanced_boundary - 2];
        ans = max(ans, total);
        total += inputs[advanced_boundary];
        total -= inputs[advanced_boundary - 2];
        return;
      }
      if (now == 2 * z || count == z) {
        return;
      }

      int boundary = k - 2 * count - 2;
      if (count < k && last <= boundary) {

        if (sums[now].second < boundary) {
          total += sums[now].first;
          total -= sums[boundary + 1].first;
          (**dfs)(now + 1, max(last, sums[now].second + 1), count + 1);
          total -= sums[now].first;
          total += sums[boundary + 1].first;
        }
      }
      (**dfs)(now + 1, last, count);
    }
  );

  (**dfs)(0, 0, 0);

  LOG_INFO << ans;
}

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

  Solver([](){solve();});

  return 0;
}

```.
1389C
namespace {
using namespace std;

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

}  // unnamed namespace;

void solve() {
  string input;
  cin >> input;

  int size = input.size();
  int ans = size - 2;

  for (char f = '0'; f <= '9'; ++f) {
    int single_count = 0;
    for (const auto &ch : input) {
      if(ch == f) ++single_count;
    }
    ans = min(ans, size - single_count);

    for (char s = '0'; s <= '9'; ++s) {
      if(s == f) continue;

      int duo_count = 0;
      bool is_f = true;

      for (const auto &ch : input) {
        if (is_f && ch == f) {
          ++duo_count;
          is_f = !is_f;
        } else if (!is_f && ch == s) {
          ++duo_count;
          is_f = !is_f;
        }
      }

      duo_count -= duo_count & 0x01;
      ans = min(ans, size - duo_count);
    }
  }

  LOG_INFO << ans;
}

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

  Solver([](){solve();});

  return 0;
}