結果
問題 |
No.438 Cwwプログラミング入門
|
ユーザー |
|
提出日時 | 2016-10-28 23:04:44 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,887 bytes |
コンパイル時間 | 1,736 ms |
コンパイル使用メモリ | 168,800 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-24 18:40:08 |
合計ジャッジ時間 | 9,414 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 56 WA * 40 RE * 2 |
ソースコード
#include <bits/stdc++.h> using namespace std; pair<long long, long long> extgcd(long long a, long long b, long long c) { if (b == 0) return make_pair(c, 0); long long x, y; tie(x, y) = extgcd(b, a % b, c); return make_pair(y, x - a / b * y); } int gcd(int x, int y) { if (y == 0) return x; return gcd(y, x % y); } string create(int x, char c) { if (x >= 10100) x = 10100; string s(1, c); for (int i = 0; i < x - 1; i++) { s += c; s += "C"; } return s; } int main() { int x, y, z; cin >> x >> y >> z; int g = gcd(x, y); if (z % g != 0) { cout << "mourennaihasimasenn" << endl; return 0; } x /= g; y /= g; z /= g; long long a, b; tie(a, b) = extgcd(x, y, z); cerr << a << " " << b << endl; while (true) { if (abs(a) + abs(b) > abs(a - y) + abs(b + x)) { a -= y; b += x; } else break; } cerr << a << " " << b << endl; string ansA; if (b == 0) { ansA = create(abs(a), 'c'); } else if (a == 0) { ansA = create(abs(b), 'w'); } else if (a > 0 && b > 0) { ansA = create(abs(a), 'c') + create(abs(b), 'w') + "C"; } else if (a < 0) { ansA = create(abs(b), 'w') + create(abs(a), 'c') + "W"; } else if (b < 0) { ansA = create(abs(a), 'c') + create(abs(b), 'w') + "W"; } while (true) { if (abs(a) + abs(b) > abs(a + y) + abs(b - x)) { a += y; b -= x; } else break; } cerr << a << " " << b << endl; string ansB; if (b == 0) { ansB = create(abs(a), 'c'); } else if (a == 0) { ansB = create(abs(b), 'w'); } else if (a > 0 && b > 0) { ansB = create(abs(a), 'c') + create(abs(b), 'w') + "C"; } else if (a < 0) { ansB = create(abs(b), 'w') + create(abs(a), 'c') + "W"; } else if (b < 0) { ansB = create(abs(a), 'c') + create(abs(b), 'w') + "W"; } if (ansA.size() > ansB.size()) swap(ansA, ansB); if (ansA.size() > 10000) { cout << "mourennaihasimasenn" << endl; } else { cout << ansA << endl; } }