結果
問題 | No.2247 01 ZigZag |
ユーザー |
|
提出日時 | 2023-03-25 02:44:33 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 2,026 bytes |
コンパイル時間 | 4,688 ms |
コンパイル使用メモリ | 206,736 KB |
最終ジャッジ日時 | 2025-02-11 17:57:21 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 50 |
ソースコード
#include <bits/stdc++.h>using namespace std;#ifdef _RUTHEN#include <debug.hpp>#else#define show(...) true#endifusing 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;V<string> ans;{V<pair<int, int>> B(K + 1);int c[2] = {};rep(i, K + 1) {B[i] = {i % 2, 1};c[i % 2]++;}if (c[0] <= N and c[1] <= M) {rep(i, K + 1) {if (i % 2 == 0) {B[i].second += N - c[0];c[0] = N;}}for (int i = K; i >= 0; i--) {if (i % 2 == 1) {B[i].second += M - c[1];c[1] = M;}}if (c[0] == N and c[1] == M) {string s;for (auto &[c, cnt] : B) s += string(cnt, c + '0');ans.push_back(s);}}}{V<pair<int, int>> B(K + 1);int c[2] = {};rep(i, K + 1) {B[i] = {(i + 1) % 2, 1};c[(i + 1) % 2]++;}if (c[0] <= N and c[1] <= M) {rep(i, K + 1) {if ((i + 1) % 2 == 0) {B[i].second += N - c[0];c[0] = N;}}for (int i = K; i >= 0; i--) {if ((i + 1) % 2 == 1) {B[i].second += M - c[1];c[1] = M;}}if (c[0] == N and c[1] == M) {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;}