結果
問題 |
No.438 Cwwプログラミング入門
|
ユーザー |
|
提出日時 | 2016-10-28 23:41:55 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,629 bytes |
コンパイル時間 | 855 ms |
コンパイル使用メモリ | 89,152 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-24 20:31:36 |
合計ジャッジ時間 | 4,342 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 96 WA * 2 |
ソースコード
#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; 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; } 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); string err = "mourennaihasimasenn"; 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) { cout << "c" << endl; return 0; } ll q = z / y; cout << "w"; REP(i, 1, q) cout << "wC"; cout << endl; return 0; } if (z == 0) { cout << "w" << endl; return 0; } ll q = z / x; cout << "c"; REP(i, 1, q) cout << "cC"; cout << endl; return 0; } x /= g, y /= g, z /= g; a *= z, b *= z; ll cost = reduce(x, y, a, b); 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 0; } 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 0; } 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 0; } cout << "ccW" << endl; } else { cout << err << endl; } }