結果
問題 | No.873 バイナリ、ヤバいなり!w |
ユーザー |
|
提出日時 | 2019-08-30 22:14:42 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,407 bytes |
コンパイル時間 | 2,091 ms |
コンパイル使用メモリ | 183,792 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-24 01:36:53 |
合計ジャッジ時間 | 4,844 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 WA * 7 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;string calc(int num, int bg) {string res = "";for (int i = 0; i < num; i++) {res += (char)('0' + bg);bg = 1 - bg;}return res;}int main() {cin.tie(0);ios::sync_with_stdio(false);int n;cin >> n;vector<int> dp(n + 1);vector<int> dp2(n + 1, 1);for (int i = 0; i <= n; i++) dp[i] = i;dp2[0] = 0;for (int i = 2; i * i <= n; i++) {for (int j = i * i; j <= n; j++) {int cost = dp[j - i * i] + i;if (dp[j] > cost) {dp[j] = cost;dp2[j] = i;}}}vector<int> odd;deque<int> even;int cur = n;while (cur > 0) {if (dp2[cur] % 2 == 1) odd.push_back(dp2[cur]);else even.push_back(dp2[cur]);cur -= dp2[cur] * dp2[cur];}sort(odd.begin(), odd.end());sort(even.begin(), even.end());string ans = "";for (int x : odd) {ans += calc(x, 0);}int bg = 0;while (!even.empty()) {if (bg == 0) {ans += calc(even.back(), bg);even.pop_back();bg = 1;} else {ans += calc(even.front(), bg);even.pop_front();bg = 0;}}cout << ans << endl;return 0;}