結果
問題 | No.2247 01 ZigZag |
ユーザー | kcvlex |
提出日時 | 2023-03-17 21:44:48 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,005 bytes |
コンパイル時間 | 3,046 ms |
コンパイル使用メモリ | 158,464 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-18 16:06:38 |
合計ジャッジ時間 | 4,499 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 50 |
ソースコード
#include <iostream> #include <atcoder/all> #define ALL(V) std::begin(V), std::end(V) std::string solve(int N, int M, int K) { if (N == 0 || M == 0) { if (K == 0) { char c = '0' + (N == 0); return std::string(N + M, c); } else { return "-1"; } } if (K == 0) return "-1"; int max = std::min(N, M) * 2 - (N == M); if (max < K) return "-1"; if (K == max && N < M) { std::string s; for (int i = 0; i < N; i++) s += "10"; s += std::string(M - N, '1'); return s; } std::string ans = "01"; N--; M--; K--; while (2 <= K) { assert(N && M); ans += "01"; K -= 2; N--; M--; } ans += std::string(M, '1'); if (K == 1) { assert(N); ans += '0'; N--; } return std::string(N, '0') + ans; } int main() { int N, M, K; std::cin >> N >> M >> K; std::cout << solve(N, M, K) << std::endl; return 0; }