結果

問題 No.438 Cwwプログラミング入門
ユーザー togari_takamoto
提出日時 2016-10-28 23:33:00
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 2,001 bytes
コンパイル時間 1,528 ms
コンパイル使用メモリ 162,064 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-24 20:15:47
合計ジャッジ時間 11,116 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 48 WA * 43 RE * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

ll extgcd(ll a, ll b, ll *x, ll *y) {
	if (b == 0) return (*x = (a<0) ? -1 : 1), *y = 0, abs(a);
	ll d = extgcd(b, a%b, y, x);
	return *y -= a / b*(*x), d;
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	ll a, b, c; cin >> a >> b >> c;
	ll x, y;
	ll d = extgcd(a, b, &x, &y);
	auto cww = [&](ll x, ll y, ll c, const string & s) {
		string C = "c", W = "w";
		if (c % d) return false;

		x *= c / d;
		y *= c / d;

		ll ans = 0;
		if (x < 0) {
			ans += -x + y + max<ll>(0, y - 1) -x;
		} else if (y < 0) {
			ans += -y + x + max<ll>(0, x - 1) - y;
		} else {
			ans += x + y + max<ll>(0, x - 1 + y);
		}
		if (s.size() + ans <= 10000) {
			string ans;
			if (x < 0) {
				REP(i, -x) ans += C;
				REP(i, y) ans += W;
				REP(i, y - 1) ans += "C";
				REP(i, -x) ans += "W";
			} else if (y < 0) {
				REP(i, -y) ans += W;
				REP(i, x) ans += C;
				REP(i, x - 1) ans += "C";
				REP(i, -y) ans += "W";
			} else {
				REP(i, x) ans += C;
				REP(i, y) ans += W;
				REP(i, y + x - 1) ans += "C";
			}
			cout << s << ans << endl;
			return true;
		}
		return false;
	};
	string s;
	REP(i, c / a) {
		if (s.size() >= 10000) break;
		if (cww(x, y, c - i*a, s)) return 0;
		if (i == 0) s = "c";
		s += "cC";
	}

	s = "" ;
	REP(i, c / b) {
		if (s.size() >= 10000) break;
		if (cww(x, y, c - i*b, s)) return 0;
		if (i == 0) s = "w";
		s += "wC";
	}
	cout << "mourennaihasimasenn" << endl;

	return 0;
}
0