結果

問題 No.2247 01 ZigZag
ユーザー ruthen71
提出日時 2023-03-17 23:17:06
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,615 bytes
コンパイル時間 2,170 ms
コンパイル使用メモリ 208,124 KB
最終ジャッジ日時 2025-02-11 14:21:22
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 49 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#ifdef _RUTHEN
#include <debug.hpp>
#else
#define show(...) true
#endif

using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T> using V = vector<T>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M, K;
    cin >> N >> M >> K;
    K++;
    V<string> ans;
    {
        // start 0
        int c0 = (K + 1) / 2, c1 = K / 2;
        if (c0 <= N and c1 <= M) {
            V<pair<int, int>> B;
            int t = 0;
            while (B.size() < K) {
                if (t == 1) {
                    B.push_back({1, 1});
                    M--;
                } else {
                    B.push_back({0, 1});
                    N--;
                }
                t ^= 1;
            }
            assert(B.size() == K);
            rep(i, K) {
                {
                    auto &[c, cnt] = B[i];
                    if (c == 0) {
                        cnt += N;
                        N = 0;
                    }
                }
                {
                    auto &[c, cnt] = B[K - 1 - i];
                    if (c == 1) {
                        cnt += M;
                        M = 0;
                    }
                }
            }
            string s;
            for (auto &[c, cnt] : B) s += string(cnt, c + '0');
            ans.push_back(s);
        }
    }
    {
        // start 1
        int c1 = (K + 1) / 2, c0 = K / 2;
        if (c0 <= N and c1 <= M) {
            V<pair<int, int>> B;
            int t = 1;
            while (B.size() < K) {
                if (t == 1) {
                    B.push_back({1, 1});
                    M--;
                } else {
                    B.push_back({0, 1});
                    N--;
                }
                t ^= 1;
            }
            assert(B.size() == K);
            rep(i, K) {
                {
                    auto &[c, cnt] = B[i];
                    if (c == 0) {
                        cnt += N;
                        N = 0;
                    }
                }
                {
                    auto &[c, cnt] = B[K - 1 - i];
                    if (c == 1) {
                        cnt += M;
                        M = 0;
                    }
                }
            }
            string s;
            for (auto &[c, cnt] : B) s += string(cnt, c + '0');
            ans.push_back(s);
        }
    }
    sort(ans.begin(), ans.end());
    if (ans.size() == 0) {
        cout << -1 << '\n';
    } else {
        cout << ans[0] << '\n';
    }
    return 0;
}
0