結果
問題 |
No.873 バイナリ、ヤバいなり!w
|
ユーザー |
![]() |
提出日時 | 2019-08-31 08:20:32 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,093 bytes |
コンパイル時間 | 2,022 ms |
コンパイル使用メモリ | 195,844 KB |
最終ジャッジ日時 | 2025-01-07 16:07:43 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 34 WA * 2 |
ソースコード
#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> ord; rep(x, 1, 10101) if(x * x <= N and x % 2 == 1) ord.push_back(x); rrep(x, 10101, 1) if(x * x <= N and x % 2 == 0) ord.push_back(x); string ans = ""; int cu = N; int lst = 0; while(1 <= cu) { fore(x, ord) if(0 <= cu - x * x) if(dp[cu - x * x] + x == dp[cu]) { rep(i, 0, x) { if(0 < i) lst = 1 - lst; ans += char('0' + lst); } cu -= x*x; break; } } cout << ans << endl; }