結果

問題 No.438 Cwwプログラミング入門
ユーザー simansiman
提出日時 2023-06-07 17:30:09
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,634 bytes
コンパイル時間 3,672 ms
コンパイル使用メモリ 142,336 KB
実行使用メモリ 825,252 KB
最終ジャッジ日時 2024-12-29 22:40:45
合計ジャッジ時間 256,564 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21 TLE * 34 MLE * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

const int INF = 99999;

string build_sub_code(int a, int b) {
  string code = "";

  for (int i = 0; i < a; ++i) {
    code += "c";
    if (i > 0) {
      code += "C";
    }
  }
  for (int i = 0; i < b; ++i) {
    code += "w";
    if (code.size() >= 2) {
      code += "C";
    }
  }

  return code;
}

string build_code(int a, int b, int c, int d) {
  string code1 = build_sub_code(a, b);
  string code2 = build_sub_code(c, d);

  if (c + d == 0) {
    return code1;
  } else {
    return code2 + code1 + "W";
  }
}

int main() {
  int X, Y, Z;
  cin >> X >> Y >> Z;
  int cnt = 0;

  map<ll, int> memo;
  map<ll, int> min_counter;

  for (int a = 0; a <= 5000; ++a) {
    for (int b = 0; b <= 5000; ++b) {
      int n = a + b;
      if (2 * n - 1 > 10000) break;
      int c = a * 10000 + b;
      ll v = a * X + b * Y;

      if (memo[v] == 0 || min_counter[v] > n) {
        min_counter[v] = n;
        memo[v] = c;
      }
    }
  }

  for (auto [k, c] : memo) {
    ll r = k - Z;
    int a = c / 10000;
    int b = c % 10000;

    if (r == 0) {
      string code = build_code(a, b, 0, 0);
      cout << code << endl;
      return 0;
    } else if (memo.count(r)) {
      int nc = memo[r];
      int na = nc / 10000;
      int nb = nc % 10000;

      string code = build_code(a, b, na, nb);
      cout << code << endl;
      return 0;
    }
  }

  cout << "NO" << endl;

  return 0;
}
0