結果
| 問題 |
No.438 Cwwプログラミング入門
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-10-30 13:52:25 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,497 bytes |
| コンパイル時間 | 1,581 ms |
| コンパイル使用メモリ | 154,440 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-12 22:15:35 |
| 合計ジャッジ時間 | 8,847 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 60 WA * 38 |
ソースコード
import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.math; // math functions
void main()
{
auto rd = readln.split.to!(long[]), x = rd[0], y = rd[1], z = rd[2];
writeln(calc(x, y, z));
}
auto calc(long x, long y, long z)
{
if (z == 0) return "ccW";
if (x == 0 && y == 0) return "NO";
if (x == 0) {
if (z % y) return "NO";
auto g = z/y;
return 'w'.repeat.take(g).chain('C'.repeat.take(g-1)).to!string;
}
if (y == 0) {
if (z % x) return "NO";
auto g = z/x;
return 'c'.repeat.take(g).chain('C'.repeat.take(g-1)).to!string;
}
auto ma = 100000L, mb = 100000L;
foreach (a; -5000L..5001L) {
if ((z-a*x)%y) continue;
auto b = (z-a*x)/y;
if (a.abs*2+b.abs*2-1 > 10000) continue;
if (a.abs*2+b.abs*2-1 < ma.abs*2+mb.abs*2-1) {
ma = a;
mb = b;
}
}
if (ma.abs*2+mb.abs*2 > 10000) return "NO";
if (ma == 0)
return 'w'.repeat.take(mb).chain('C'.repeat.take(mb-1)).to!string;
if (mb == 0)
return 'c'.repeat.take(ma).chain('C'.repeat.take(ma-1)).to!string;
if (ma < 0)
return 'w'.repeat.take(mb).chain('C'.repeat.take(mb-1))
.chain('c'.repeat.take(-ma)).chain('W'.repeat.take(-ma)).to!string;
if (mb < 0)
return 'c'.repeat.take(ma).chain('C'.repeat.take(ma-1))
.chain('w'.repeat.take(-mb)).chain('W'.repeat.take(-mb)).to!string;
return 'c'.repeat.take(ma).chain('C'.repeat.take(ma-1))
.chain('w'.repeat.take(mb)).chain('C'.repeat.take(mb)).to!string;
}