結果

問題 No.438 Cwwプログラミング入門
ユーザー kimiyuki
提出日時 2016-10-28 23:54:10
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,391 bytes
コンパイル時間 761 ms
コンパイル使用メモリ 75,372 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2024-11-24 21:17:37
合計ジャッジ時間 11,003 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 94 RE * 2 TLE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <deque>
#include <algorithm>
#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; }
string solve(ll x, ll y, ll z) {
    const int limit = 10000;
    for (ll b = -limit/2; b <= limit/2; ++ b) {
        ll a = x == 0
            ? (b < 0 ? 1 : 0)
            : (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;
    int d = gcd(x, y);
    string ans;
    if (z % d == 0) ans = solve(x / d, y / d, z / d);
    if (ans.empty()) ans = "mourennaihasimasenn";
    cout << ans << endl;
    return 0;
}
0