(200625) 코드포스 - Educational Codeforces Round 90

Contest Link: Educational Codeforces Round 90 (Rated for Div. 2) - Codeforces

ABCD 풀었습니다.
E번은 풀어봤는데 오답이네요 ㅋㅋ 생각한대로 했는데 예외가 있군요 끙

Edu90A
namespace {
using namespace std;

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

int main(int argc, char** argv) {
  ios::sync_with_stdio(false); 
  cin.tie(NULL);
  LOG(DEBUG).Open();

  int test_case;
  cin >> test_case;

  while (test_case--) {
    int64_t a, b, c;
    cin >> a >> b >> c;

    int64_t ans1, ans2;
    if (a >= c) {
      ans1 = -1;
      ans2 = b;
    } else {
      ans1 = 1;
      if(a * b > c) {
        ans2 = b;
      } else {
        ans2 = -1;
      }
    }
    LOG(INFO) << ans1 << ' ' << ans2;
  }
  return 0;
}

Edu90B
namespace {
using namespace std;

INIT_STRING_ANSWER("DA", "NET");
}  // unnamed namespace;


int main(int argc, char** argv) {
  ios::sync_with_stdio(false); 
  cin.tie(NULL);
  LOG(DEBUG).Open();

  int test_case;
  cin >> test_case;

  while (test_case--) {
    string input;
    cin >> input;

    size_t count[2] = {0, 0};
    for (auto c : input) {
      ++count[c == '1'];
    }

    size_t min_value = min(count[0], count[1]);

    LOG_INFO << GET_ANSWER(min_value & 0x01);
  }
  return 0;
}

Edu90C
namespace {
using namespace std;

INIT_STRING_ANSWER("Yes", "No");

constexpr int64_t kMaxS = 1 + 10e6;
}  // unnamed namespace;


int main(int argc, char** argv) {
  ios::sync_with_stdio(false); 
  cin.tie(NULL);
  LOG(DEBUG).Open();

  int test_case;
  cin >> test_case;

  while (test_case--) {
    string input;
    cin >> input;

    vector<int64_t> shortests(input.size() + 1, 0);

    int64_t count = 0;
    for (size_t i = 0; i < input.size(); ++i) {
      if (input[i] == '-') count += 1;
      else count -= 1;

      if (count > 0) {
        if(shortests[count - 1] == 0) shortests[count - 1] = i + 1;
      }
    }

    int64_t ans = 0;
    for(auto shortest : shortests) {
      if(shortest == 0) {
        ans += static_cast<int64_t>(input.size());
        break;
      }
      ans += shortest;
    }

    LOG(INFO) << ans;
  }
  return 0;
}

Edu90D
namespace {
using namespace std;

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


int main(int argc, char** argv) {
  ios::sync_with_stdio(false); 
  cin.tie(NULL);
  LOG(DEBUG).Open();

  int test_case;
  cin >> test_case;

  while (test_case--) {
    int n;
    cin >> n;

    vector<int64_t> benefits1(n / 2);
    vector<int64_t> benefits2((n - 1) / 2);

    int64_t benefit1, benefit2;
    int64_t ans_base;
    cin >> ans_base;
    benefit1 = -ans_base;
    for (int i = 1; i < n; ++i) {
      int64_t input;
      cin >> input;
      if (i & 0x01) {
        benefit1 += input;
        benefits1[i/2] = benefit1;

        benefit2 = input;
      } else {
        benefit1 = -input;
        
        benefit2 -= input;
        benefits2[(i-1) / 2] = benefit2;

        ans_base += input;
      }
    }

    int64_t candi1 = 0, candi2 = 0;
    int64_t sum = 0;
    for (auto benefit : benefits1) {
      sum += benefit;

      if(sum < 0) sum = 0;
      else candi1 = max(sum, candi1);
    }

    sum = 0;
    for (auto benefit : benefits2) {

      sum += benefit;

      if(sum < 0) sum = 0;
      else candi2 = max(sum, candi2);
    }

    LOG(INFO) << ans_base + max(candi1, candi2);
  }
  return 0;
}

Edu90E 오답

맨 앞이랑 맨 뒤만 올리면서 중간에 9를 채워넣었는데,
28 , 1에서 189가 정답인게 있내요 :frowning:

namespace {
using namespace std;

INIT_STRING_ANSWER("Yes", "No");

constexpr int64_t kMaxNow = 1e18;
}  // unnamed namespace;

string dp[151][10];

int main(int argc, char** argv) {
  ios::sync_with_stdio(false); 
  cin.tie(NULL);
  LOG(DEBUG).Open();

  int test_case;
  cin >> test_case;

  array<vector<int64_t>, 10> answers;
  fill(answers.begin(), answers.end(),vector<int64_t>(151, -1));

  auto sum_digit = [&](int64_t number) -> int{
    int ret = 0;
    while(number > 0) {
      ret += number % 10;
      number /= 10;
    }
    return ret;
  };

  int64_t now = 0;

  while (now < kMaxNow) {
    for (int i = 0; i <= 9; ++i) {
      int sum = 0;
      for(int j = 0; j <= i; ++j) {
        sum += sum_digit(now + j);
      }
      if(sum <= 150) {
        if(answers[i][sum] == -1) answers[i][sum] = now;
      }
    }

    now += 1;
    if((now % 10) == 0) {
      int64_t digit_count = 0;
      int64_t temp = now;
      while (temp > 0) {
        ++digit_count;
        temp /= 10;
      }
      
      int64_t add = 0;
      for( int k = 2; k < digit_count; k++) {
        add *= 10;
        add += 9;
      }
      add *= 10;

      now += add;
    }
  }

  while (test_case--) {
    int n, k;
    cin >> n >> k;

    LOG(INFO) << answers[k][n];
  }
  
  return 0;
}

Edu90E 정답

맨뒤를 10개만 보는 것을 100개 보는 것으로 늘렸더니 통과는 되네요 ㅋㅋ

깔끔한 코드가 보고 싶으시면 red coder 정답 참조하세용.

대충 봐서는 비슷한 방식으로 하는 느낌인데, 분석을 좀 해야겠군요.

namespace {
using namespace std;

INIT_STRING_ANSWER("Yes", "No");

constexpr int64_t kMaxNow = 1e18;
}  // unnamed namespace;

string dp[151][10];

int main(int argc, char** argv) {
  ios::sync_with_stdio(false); 
  cin.tie(NULL);
  LOG(DEBUG).Open();

  int test_case;
  cin >> test_case;

  array<vector<int64_t>, 10> answers;
  fill(answers.begin(), answers.end(),vector<int64_t>(151, -1));

  auto sum_digit = [&](int64_t number) -> int{
    int ret = 0;
    while(number > 0) {
      ret += number % 10;
      number /= 10;
    }
    return ret;
  };

  int64_t now = 0;

  while (now < kMaxNow) {
    for (int i = 0; i <= 9; ++i) {
      int sum = 0;
      for(int j = 0; j <= i; ++j) {
        sum += sum_digit(now + j);
      }
      if(sum <= 150) {
        if(answers[i][sum] == -1) answers[i][sum] = now;
      }
    }

    now += 1;
    if((now % 100) == 0) {
      int64_t digit_count = 0;
      int64_t temp = now;
      while (temp > 0) {
        ++digit_count;
        temp /= 10;
      }
      
      int64_t add = 0;
      for( int k = 3; k < digit_count; k++) {
        add *= 10;
        add += 9;
      }
      add *= 100;

      now += add;
    }
  }

  while (test_case--) {
    int n, k;
    cin >> n >> k;

    LOG(INFO) << answers[k][n];
  }
  
  return 0;
}

predefined namespace, macros, header including 부분은 중복 코드라 앞으로 따로 올릴게요.

#include <algorithm>
#include <cmath>
#include <functional> 
#include <iostream>
#include <queue>
#include <string>
#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 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)

대다내…

1 Like

꾸준함 정말 대단하십니다

1 Like

@Eride
ㅎㅎ 아직은 대단하지 못합니다 :sob:

@outersky
같이 풀 아우타 구함 ㅎㅎ
작심삼일은 일단 넘긴거 같긴한데 아직 패턴으로 녹이려면 좀 더 의식적으로 해야겠죠.

2 Likes