結果
問題 | No.873 バイナリ、ヤバいなり!w |
ユーザー |
![]() |
提出日時 | 2020-07-29 15:58:00 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 866 ms / 2,000 ms |
コード長 | 2,156 bytes |
コンパイル時間 | 2,052 ms |
コンパイル使用メモリ | 196,484 KB |
最終ジャッジ日時 | 2025-01-12 07:36:10 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define rep(i,n) REP(i,0,n)#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)#define repr(i, n) REPR(i, n, 0)#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)#define all(r) r.begin(),r.end()#define rall(r) r.rbegin(),r.rend()typedef long long ll;typedef vector<int> vi;typedef vector<ll> vl;const ll INF = 1e18;const ll MOD = 1e9 + 7;template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}#define DEBUG_MODE#ifdef DEBUG_MODE#define dump(x) cout << #x << " : " << x << " "#define dumpL(x) cout << #x << " : " << x << '\n'#define LINE cout << "line : " << __LINE__ << " "#define LINEL cout << "line : " << __LINE__ << '\n'#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << " "#define dumpVL(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl#define STOP assert(false)#else#define dump(x)#define dumpL(x)#define LINE#define LINEL#define dumpV(v)#define dumpVL(v)#define STOP assert(false)#endif#define mp make_pairnamespace std {template<class S, class T>ostream &operator <<(ostream& out, const pair<S, T>& a) {out << '(' << a.fi << ", " << a.se << ')';return out;}}void update(string& a, const string& b) {if(a.empty()) a = b;else if(a.size() > b.size() || a > b) a = b;}string calc(int n) {string str;while((int)str.size() < n+20) {char c = '0' + (str.size()%2);str += c;}vector<string> dp(n+10);auto check = [&](int i, int j) {int k = i+j*j;return dp[k].empty() || (dp[k].size() >= dp[i].size() + j);};rep(i, dp.size()) {for(int j = 1; j*j+i < (int)dp.size(); ++j) {if(check(i, j)) {if(i == 0) update(dp[j*j], str.substr(0, j));else update(dp[i+j*j], dp[i] + str.substr((dp[i].back() == '1'), j));}}}return dp[n];}int main(){int n;cin >> n;cout << calc(n) << '\n';return 0;}