結果
問題 |
No.438 Cwwプログラミング入門
|
ユーザー |
![]() |
提出日時 | 2016-04-30 01:53:57 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,939 bytes |
コンパイル時間 | 1,722 ms |
コンパイル使用メモリ | 175,300 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-24 18:12:09 |
合計ジャッジ時間 | 10,424 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 70 WA * 4 RE * 24 |
ソースコード
/* * Problem link * http://yukicoder.me/problems/1100 */ #include<bits/stdc++.h> using namespace std; struct INIT{INIT(){cin.tie(0);ios_base::sync_with_stdio(false);} }init; typedef long long LL; inline bool inner(LL x,LL lb,LL ub) { return(lb <= x && x <= ub); } #define SZ 100000 pair<char, char> _used[SZ * 2 + 1]; /*小さいケースならBFSで最適解が求まる*/ int main() { #ifdef INPUT_FROM_FILE ifstream cin("sample.in"); ofstream cout("sample.out"); #endif LL x, y, z; cin >> x >> y >> z; assert(inner(x, 0, 100000000)); assert(inner(y, 0, 100000000)); assert(inner(z, 0, 100000000)); fill(_used, _used + SZ * 2 + 1, make_pair('-', '-')); pair<char, char> *used = _used + SZ; queue<LL> que; used[x] = make_pair('c', '-'); used[y] = make_pair('w', '-'); que.push(x); que.push(y); while (que.empty() == false) { auto v = que.front();que.pop(); if (inner(v + x, -SZ, SZ) && used[v + x].first == '-') { used[v + x] = make_pair('c', 'C'); que.push(v + x); } if (inner(v - x, -SZ, SZ) && used[v - x].first == '-') { used[v - x] = make_pair('c', 'W'); que.push(v - x); } if (inner(v + y, -SZ, SZ) && used[v + y].first == '-') { used[v + y] = make_pair('w', 'C'); que.push(v + y); } if (inner(v - y, -SZ, SZ) && used[v - y].first == '-') { used[v - y] = make_pair('w', 'W'); que.push(v - y); } } if (inner(z, -SZ, SZ) == false || used[z].first == '-') { cout << "mourennaihasimasenn" << endl; return 0; } LL v = z; string p, q; while (true) { p += used[v].first; if (used[v].second == '-')break; q += used[v].second; if (used[v].first == 'c'&&used[v].second == 'C')v = v - x; else if (used[v].first == 'c'&&used[v].second == 'W')v = v + x; else if (used[v].first == 'w'&&used[v].second == 'C')v = v - y; else if (used[v].first == 'w'&&used[v].second == 'W')v = v + y; }; reverse(q.begin(), q.end()); cout << p + q << endl; return 0; }