結果

問題 No.438 Cwwプログラミング入門
ユーザー h_noson
提出日時 2016-10-28 23:35:07
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,060 bytes
コンパイル時間 903 ms
コンパイル使用メモリ 86,744 KB
実行使用メモリ 251,068 KB
最終ジャッジ日時 2024-11-24 20:17:24
合計ジャッジ時間 15,902 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 2
other AC * 11 WA * 85 RE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b,a%b);
}

int extgcd(int a, int b, int& x, int& y) {
    int d = a;
    if (b != 0) {
        d = extgcd(b,a%b,y,x);
        y -= a/b*x;
    }
    else {
        x = 1;
        y = 0;
    }
    return d;
}

int main(void) {
    int x, y, z;
    char c = 'c', w = 'w';
    cin >> x >> y >> z;
    if (z % gcd(x,y) != 0) {
        cout << "mourennaihasimasen" << endl;
        return 0;
    }
    if (x < y) {
        swap(x,y);
        swap(c,w);
    }
    string ans = "ccW";
    while (z >= x) {
        ans += c;
        ans += 'C';
        z -= x;
        if (ans.size() > 10000) {
            cout << "mourennaihasimasen" << endl;
            return 0;
        }
    }
    while (z >= y) {
        ans += w;
        ans += 'C';
        z -= y;
        if (ans.size() > 10000) {
            cout << "mourennaihasimasen" << endl;
            return 0;
        }
    }
    int a, b;
    int d = extgcd(x,y,a,b);
    string str;
    while (a > 0) {
        str += c;
        str += 'C';
        a--;
    }
    while (a < 0) {
        str += c;
        str += 'W';
        a++;
    }
    while (b > 0) {
        str += w;
        str += 'C';
        b--;
    }
    while (b < 0) {
        str += w;
        str += 'W';
        b++;
    }
    if (ans.size() + z / d * str.size() > 10000) {
        cout << "mourennaihasimasen" << endl;
        return 0;
    }
    while (z > 0) {
        ans += str;
        z -= d;
    }
    cout << ans << endl;
    return 0;
}
0