結果
| 問題 |
No.438 Cwwプログラミング入門
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-10-28 23:23:37 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,305 bytes |
| コンパイル時間 | 1,839 ms |
| コンパイル使用メモリ | 172,504 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-24 19:57:12 |
| 合計ジャッジ時間 | 5,400 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 96 WA * 2 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
vector<long long> exgcd(long long a, long long b){
if(b==0) return vector<long long>{1, 0, a};
auto res = exgcd(b, a%b);
return vector<long long>{res[1], res[0]-a/b*res[1], res[2]};
}
char NG[] = "mourennaihasimasenn";
const int LIM = 10000, MA = 100000000;
int main(){
ll x, y, z;
cin >> x >> y >> z;
// if(x > y)swap(y, x);
// x<=y
/*
if(x == 0 && y == 0) {
if(z == 0) {
puts("c");
} else {
puts(NG);
}
} else if(x == 0 || y == 0) {
if(z == 0) {
puts("c");
} else if(z%y ) {
if(z == y) {
puts("w");
} else if(y / z * 2 - 1 <= LIM) {
int num = y / z;
string ans = string(num, 'w')+
} else {
puts(NG);
}
} else {
puts(NG);
}
} else {
}*/
if(x == 0 && y == 0) {
if(z == 0) {
puts("c");
} else {
puts(NG);
}
return 0;
}
if(z == 0) {
if(x == 0) {
puts("c");
return 0;
}
if(y == 0) {
puts("w");
return 0;
}
}
// xだけ
for(int a = 1; a <= LIM; ++a){
ll val = a*x;
int len = a + (a > 1 ? a - 1 : 0);
if(val == z && len <= LIM) {
string ans = string(a, 'c');
if(a > 1)ans += string(a - 1, 'C');
printf("%s\n", ans.c_str());
return 0;
}
}
// yだけ
for(int a = 1; a <= LIM; ++a){
ll val = a*y;
int len = a + (a > 1 ? a - 1 : 0);
if(val == z && len <= LIM) {
string ans = string(a, 'w');
if(a > 1)ans += string(a - 1, 'C');
printf("%s\n", ans.c_str());
return 0;
}
}
if(x == 0 || y == 0) {
puts(NG);
return 0;
}
string ans;
// x!=0 && y != 0
for(int a = -LIM; a <= LIM; ++a) if(a){
ll need = z - a*x;
// need != 0
if(need%y == 0) {
ll b = need / y;
ll cost = 2*abs(a) + 2*abs(b) -1;
if(cost > LIM || b == 0)continue;
if(a > 0 && b > 0) {
ans = string(a, 'c') + string(b, 'w') + string(a + b - 1, 'C');
} else if(a > 0 && b < 0) {
b = abs(b);
ans = string(b, 'w') + string(b - 1, 'C') + string(a, 'c') + string(a-1, 'C') + string(1,'W');
} else { // a < 0 && b > 0
a = abs(a);
ans = string(a, 'c') + string(a - 1, 'C') + string(b, 'w') + string(b-1, 'C') + string(1,'W');
}
printf("%s\n", ans.c_str());
return 0;
}
}
puts(NG);
}