結果
問題 |
No.438 Cwwプログラミング入門
|
ユーザー |
|
提出日時 | 2017-10-30 13:41:21 |
言語 | D (dmd 2.109.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,341 bytes |
コンパイル時間 | 1,662 ms |
コンパイル使用メモリ | 154,892 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-12 22:15:22 |
合計ジャッジ時間 | 11,483 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 2 |
other | AC * 42 WA * 56 |
ソースコード
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; } foreach (a; -5000L..5001L) { if ((z-a*x)%y) continue; auto b = (z-a*x)/y; if (a*2+b*2-1 > 10000) continue; if (a == 0) return 'w'.repeat.take(b).chain('C'.repeat.take(b-1)).to!string; if (b == 0) return 'c'.repeat.take(a).chain('C'.repeat.take(a-1)).to!string; if (a < 0) return 'w'.repeat.take(b).chain('C'.repeat.take(b-1)) .chain('c'.repeat.take(-a)).chain('W'.repeat.take(-a)).to!string; if (b < 0) return 'c'.repeat.take(a).chain('C'.repeat.take(a-1)) .chain('w'.repeat.take(-b)).chain('W'.repeat.take(-b)).to!string; return 'c'.repeat.take(a).chain('C'.repeat.take(a-1)) .chain('w'.repeat.take(b)).chain('C'.repeat.take(b)).to!string; } return "NO"; }