結果

問題 No.438 Cwwプログラミング入門
ユーザー pekempey
提出日時 2016-10-28 22:45:55
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
MLE  
実行時間 -
コード長 1,184 bytes
コンパイル時間 1,421 ms
コンパイル使用メモリ 165,144 KB
実行使用メモリ 816,532 KB
最終ジャッジ日時 2024-11-24 18:20:10
合計ジャッジ時間 87,176 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1 MLE * 1
other AC * 30 WA * 29 RE * 2 MLE * 21 OLE * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 == 1) return string(1, c);
	string s = create(x / 2, c);
	s = s + s + "C";
	if (x % 2 == 0) {
		return s;
	} else {
		return s + string(1, c) + "C";
	}
}

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);

	if (b == 0) {
		cout << create(abs(a), 'c') << endl;
	} else if (a == 0) {
		cout << create(abs(b), 'w') << endl;
	} else if (a > 0 && b > 0) {
		cout << create(abs(a), 'c');
		cout << create(abs(b), 'w');
		cout << "C" << endl;
	} else if (a < 0) {
		cout << create(abs(b), 'w');
		cout << create(abs(a), 'c');
		cout << "W" << endl;
	} else if (b < 0) {
		cout << create(abs(a), 'c');
		cout << create(abs(b), 'w');
		cout << "W" << endl;
	}
}
0