結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー はまやんはまやん
提出日時 2019-08-31 08:53:45
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 162 ms / 2,000 ms
コード長 2,744 bytes
コンパイル時間 2,459 ms
コンパイル使用メモリ 197,180 KB
最終ジャッジ日時 2025-01-07 16:07:53
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
           _
     _ ´<_   Welcome to My Coding Space!
     ´_` /  ⌒i @hamayanhamayan
           | |
    /   //  |
  __(__ニ/  _/ .| .|____
     /____/ u 
---------------------------------------------------------------------------------------------------*/
int N;
int dp[301010];
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> N;
rep(i, 0, 301010) dp[i] = inf;
dp[0] = 0;
rep(i, 1, N + 1) rep(x, 1, 10101) {
if(i - x * x < 0) break;
chmin(dp[i], dp[i - x * x] + x);
}
vector<int> odd;
rep(x, 1, 10101) if(x * x <= N and x % 2 == 1) odd.push_back(x);
vector<int> even;
rep(x, 1, 10101) if(x * x <= N and x % 2 == 0) even.push_back(x);
int even_num = even.size();
string ans = "";
int cu = N;
int lst = 0;
while(1 <= cu) {
int use = -1;
fore(x, odd) if(0 <= cu - x * x) if(dp[cu - x * x] + x == dp[cu]) {
use = x;
break;
}
if(use < 0) {
if(lst == 0) {
rrep(i, even_num - 1, 0) {
int x = even[i];
if(0 <= cu - x * x) if(dp[cu - x * x] + x == dp[cu]) {
use = x;
break;
}
}
} else {
fore(x, even) {
if(0 <= cu - x * x) if(dp[cu - x * x] + x == dp[cu]) {
use = x;
break;
}
}
}
}
rep(i, 0, use) {
if(0 < i) lst = 1 - lst;
ans += char('0' + lst);
}
cu -= use * use;
}
cout << ans << endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0