結果

問題 No.438 Cwwプログラミング入門
ユーザー koba-e964koba-e964
提出日時 2016-10-28 23:45:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,588 bytes
コンパイル時間 747 ms
コンパイル使用メモリ 90,604 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-18 15:32:57
合計ジャッジ時間 6,208 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 1 ms
4,376 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 2 ms
4,376 KB
testcase_52 AC 1 ms
4,376 KB
testcase_53 AC 2 ms
4,376 KB
testcase_54 AC 1 ms
4,376 KB
testcase_55 AC 2 ms
4,380 KB
testcase_56 AC 1 ms
4,376 KB
testcase_57 AC 1 ms
4,376 KB
testcase_58 AC 2 ms
4,380 KB
testcase_59 AC 2 ms
4,376 KB
testcase_60 AC 2 ms
4,376 KB
testcase_61 AC 2 ms
4,376 KB
testcase_62 AC 1 ms
4,376 KB
testcase_63 AC 2 ms
4,380 KB
testcase_64 AC 1 ms
4,380 KB
testcase_65 AC 2 ms
4,376 KB
testcase_66 AC 2 ms
4,376 KB
testcase_67 AC 2 ms
4,380 KB
testcase_68 AC 1 ms
4,380 KB
testcase_69 AC 2 ms
4,380 KB
testcase_70 AC 2 ms
4,376 KB
testcase_71 AC 2 ms
4,380 KB
testcase_72 AC 1 ms
4,380 KB
testcase_73 AC 1 ms
4,376 KB
testcase_74 AC 2 ms
4,376 KB
testcase_75 AC 2 ms
4,376 KB
testcase_76 AC 2 ms
4,380 KB
testcase_77 AC 2 ms
4,384 KB
testcase_78 AC 1 ms
4,380 KB
testcase_79 AC 1 ms
4,376 KB
testcase_80 AC 2 ms
4,376 KB
testcase_81 AC 2 ms
4,376 KB
testcase_82 AC 1 ms
4,376 KB
testcase_83 AC 2 ms
4,376 KB
testcase_84 AC 2 ms
4,384 KB
testcase_85 AC 2 ms
4,376 KB
testcase_86 AC 2 ms
4,376 KB
testcase_87 AC 2 ms
4,376 KB
testcase_88 AC 1 ms
4,376 KB
testcase_89 AC 2 ms
4,380 KB
testcase_90 AC 2 ms
4,380 KB
testcase_91 AC 2 ms
4,380 KB
testcase_92 AC 2 ms
4,380 KB
testcase_93 AC 2 ms
4,380 KB
testcase_94 AC 1 ms
4,376 KB
testcase_95 AC 2 ms
4,376 KB
testcase_96 AC 1 ms
4,376 KB
testcase_97 AC 2 ms
4,380 KB
testcase_98 AC 2 ms
4,376 KB
testcase_99 AC 2 ms
4,376 KB
testcase_100 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;
string err = "mourennaihasimasenn";


ll ex_gcd(ll x, ll y, ll &a, ll &b) {
  if (y == 0) {
    a = 1;
    b = 0;
    return x;
  }
  ll q = x / y;
  ll r = x % y;
  ll res = ex_gcd(y, r, a, b);
  ll tmp = a - q * b;
  a = b;
  b = tmp;
  return res;
}

// gcd(x, y) == 1
ll reduce(ll x, ll y, ll &a, ll &b) {
  if (x > y) {
    return reduce(y, x, b, a);
  }
  ll q = b / x;
  a += q * y;
  b -= q * x;
  ll mi = 1e16;
  ll mi_d = -10001;
  REP(d, -10000, 10000) {
    ll ad = a + y * d;
    ll bd = b - x * d;
    ll c = abs(ad) + abs(bd);
    c = 2 * c - 1;
    if (mi > c) {
      mi = c;
      mi_d = d;
    }
  }
  a += mi_d * y;
  b -= mi_d * x;
  return mi;
}

void print(ll a, ll b) {
  ll cost = 2 * (abs(a) + abs(b)) - 1;
  if (cost <= 10000) {
      // print
    if (a < 0) {
      REP(i, 0, -a) cout << 'c';
      cout << 'w';
      REP(i, 0, -a) cout << 'W';
      REP(i, 1, b) cout << "wC";
      cout << endl;
      return;
    }
    if (b < 0) {
      REP(i, 0, -b) cout << 'w';
      cout << 'c';
      REP(i, 0, -b) cout << 'W';
      REP(i, 1, a) cout << "cC";
      cout << endl;
      return;
    }
    if (a >= 0 && b >= 0 && a + b > 0) {
      REP(i, 0, a) cout << 'c';
      REP(i, 0, b) cout << 'w';
      REP(i, 1, a + b) cout << 'C';
      cout << endl;
      return;
    }
    cout << "ccW" << endl;
  } else {
    cout << err << endl;
  }
}
int main(void){
  ll x, y, z;
  cin >> x >> y >> z;
  ll a, b;
  ll g = ex_gcd(x, y, a, b);
  assert (x * a + y * b == g);
  if (x + y == 0) {
    cout << (z == 0 ? "c" : err) << endl;
    return 0;
  }
  if (z % g != 0) {
    cout << err << endl;
    return 0;
  }
  if (x * y == 0) {
    if (x == 0) {
      if (z == 0) { print(1, 0); return 0; }
      ll q = z / y;
      print(0, q);
      return 0;
    }
    if (z == 0) { print(0, 1); return 0; }
    ll q = z / x;
    print(q, 0);
    return 0;
  }
  x /= g, y /= g, z /= g;
  a *= z, b *= z;
  ll cost = reduce(x, y, a, b);
  print(a, b);
}
0