結果
問題 | No.438 Cwwプログラミング入門 |
ユーザー |
|
提出日時 | 2016-10-29 00:06:14 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,880 bytes |
コンパイル時間 | 1,020 ms |
コンパイル使用メモリ | 77,848 KB |
実行使用メモリ | 13,640 KB |
最終ジャッジ日時 | 2024-11-24 22:06:16 |
合計ジャッジ時間 | 16,367 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 56 WA * 37 RE * 3 TLE * 2 |
ソースコード
#include <iostream>#include <deque>#include <algorithm>#include <cassert>#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))#define repeat_from(i,m,n) for (int i = (m); (i) < (n); ++(i))typedef long long ll;using namespace std;ll gcd(ll a, ll b) { while (a) { b %= a; swap(a, b); } return b; }const int limit = 10000;string solve0(ll z) {return z == 0 ? "ccW" : "";}string solve1(ll x, ll z, char c) {assert (x > 0);if (z % x == 0) {int a = z / x;if (2*a-1 <= limit) {return string(a, c) + string(a-1, 'C');}}return "";}string solve2(ll x, ll y, ll z) {assert (x > 0);assert (y > 0);for (ll b = -limit/2; b <= limit/2; ++ b) {ll a = (z - y*b) / x;if (a*x + y*b == z) {deque<char> s;if (a > 0) {s.push_back('c');-- a;} else if (b > 0) {s.push_back('w');-- b;} else {s.push_back('c');s.push_back('c');s.push_back('W');}if (s.size() + 2*abs(a) + 2*abs(b) > limit) continue;repeat (i, abs(a)) { s.push_front('c'); s.push_back(a > 0 ? 'C' : 'W'); }repeat (i, abs(b)) { s.push_front('w'); s.push_back(b > 0 ? 'C' : 'W'); }return string(s.begin(), s.end());}}return "";}int main() {int x, y, z; cin >> x >> y >> z;string ans;if (ans.empty()) ans = solve0(z);if (ans.empty()) if (x != 0) ans = solve1(x, z, 'c');if (ans.empty()) if (y != 0) ans = solve1(y, z, 'w');if (ans.empty()) { int d = gcd(x, y); if (z % d == 0) ans = solve2(x / d, y / d, z / d); }if (ans.empty()) ans = "mourennaihasimasenn";if (ans.size() > 300 ) ans.resize(300);cout << ans << endl;return 0;}