結果
問題 |
No.873 バイナリ、ヤバいなり!w
|
ユーザー |
![]() |
提出日時 | 2019-08-30 22:01:26 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,217 bytes |
コンパイル時間 | 1,973 ms |
コンパイル使用メモリ | 172,988 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-24 01:31:39 |
合計ジャッジ時間 | 3,755 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 WA * 22 |
ソースコード
#include <bits/stdc++.h> int ri() { int n; assert(scanf("%d", &n) == 1); return n; } int main () { int n = ri(); std::pair<int, int> dp[n + 1];// {val, cost} for (int i = 0; i <= n; i++) dp[i] = {1000000000, -1}; dp[n] = {0, 0}; for (int i = n; i >= 0; i--) { for (int j = 0; j * j <= i; j++) { if (dp[i - j * j].first > dp[i].first + j) { dp[i - j * j].first = dp[i].first + j; dp[i - j * j].second = j; } } } std::vector<int> rens; int cur = 0; while (cur < n) { rens.push_back(dp[cur].second); cur += dp[cur].second * dp[cur].second; } assert(cur == n); /* for (auto i : rens) std::cerr << i << " "; std::cerr << std::endl;*/ std::vector<int> odds, evens; for (auto i : rens) (i % 2 ? odds : evens).push_back(i); std::reverse(evens.begin(), evens.end()); std::string res; for (auto i : odds) { if (!res.size()) res.push_back('0'); else res.push_back(res.back()); for (int j = 0; j + 1 < i ; j++) res.push_back(!(res.back() - '0') + '0'); } for (auto i : evens) { if (!res.size()) res.push_back('0'); else res.push_back(res.back()); for (int j = 0; j + 1 < i ; j++) res.push_back(!(res.back() - '0') + '0'); } std::cout << res << std::endl; return 0; }