結果
| 問題 | No.873 バイナリ、ヤバいなり!w | 
| コンテスト | |
| ユーザー |  risujiroh | 
| 提出日時 | 2019-08-30 21:48:09 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                            (最新) 
                                AC
                                 
                            (最初) | 
| 実行時間 | - | 
| コード長 | 872 bytes | 
| コンパイル時間 | 1,755 ms | 
| コンパイル使用メモリ | 174,876 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-24 01:24:57 | 
| 合計ジャッジ時間 | 3,498 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 33 WA * 3 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> dp(n + 1, 1e9);
  dp[0] = 0;
  for (int i = 1; i * i <= n; ++i) {
    for (int x = 0; x + i * i <= n; ++x) {
      dp[x + i * i] = min(dp[x + i * i], dp[x] + i);
    }
  }
  V<> v;
  while (n) {
    for (int i = 1; ; ++i) if (dp[n] == dp[n - i * i] + i) {
      v.push_back(i);
      n -= i * i;
      break;
    }
  }
  sort(begin(v), end(v), [&](int a, int b) {
    return make_pair(~a & 1, a & 1 ? a : -a) < make_pair(~b & 1, b & 1 ? b : -b);
  });
  n = v.size();
  int t = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < v[i]; ++j) {
      cout << (t + j & 1);
    }
    t += v[i] + 1;
  }
  cout << '\n';
}
            
            
            
        