結果
| 問題 |
No.873 バイナリ、ヤバいなり!w
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2024-02-25 20:36:45 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,473 bytes |
| コンパイル時間 | 1,533 ms |
| コンパイル使用メモリ | 138,520 KB |
| 最終ジャッジ日時 | 2025-02-19 21:24:15 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | TLE * 1 -- * 35 |
ソースコード
//yukicoder@cpp17
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <climits>
#include <cassert>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <random>
#include <bitset>
#include <complex>
#include <utility>
#include <numeric>
#include <functional>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 998244353;
const ll MODx = 1000000007;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62LL)-1;
const double EPS = (1e-10);
P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
計算量は変わらないが楽できるシリーズ
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる
*/
/* comment outed because can cause bugs
__attribute__((constructor))
void initial() {
cin.tie(0);
ios::sync_with_stdio(false);
}
*/
// 整数型を取得することを想定
template <typename T>
T CeilExactSqrt(int c, T x){
T mn = 0;
T mx = x;
while(mx-mn > 1){
T ce = (mn+mx)/2;
T nw = 1;
for(int i = 0; c > i; i++){
if(x/ce < nw){
mx = ce;
break;
}
nw *= ce;
if(i+1 == c && x == nw){
mx = ce;
}
}
if(mx != ce)mn = ce;
}
return mx;
}
template <typename T>
T FloorExactSqrt(int c, T x){
T mn = 0;
T mx = x;
while(mx-mn > 1){
T ce = (mn+mx)/2;
T nw = 1;
for(int i = 0; c > i; i++){
if(x/ce < nw){
mx = ce;
break;
}
nw *= ce;
}
if(mx != ce)mn = ce;
}
return mn;
}
struct d{
int n, i;
bool operator<(const d a)const{
if(n == a.n)return i < a.i;
return n < a.n;
}
};
map<d, int> X;
int b(int n, int i){
if(n == 0 || i == 1){
X[{n,i}] = n;
return n;
}
else{
int mn = n+1;
int mnj = -1;
for(int j = 0; n/(i*i) >= j; j++){
int x = (b(n-j*(i*i), i-1)+j*i);
if(x < mn){
mn = x;
mnj = j;
}
}
X[{n,i}] = mnj;
return mn;
}
}
void zig(int x, char s){
for(int i = 0; x > i; i++){
cout << s;
s = (s == '0' ? '1' : '0');
}
}
int main(){
long long n;cin>>n;
if(n == 1){
cout << "0" << endl;
return 0;
}
b(n, FloorExactSqrt(2, n));
int nwn = n;
int i = FloorExactSqrt(2, n);
vector<int> Z;
while(X.find({nwn, i}) != X.end()){
for(int j = 0; X[{nwn, i}] > j; j++){
Z.push_back(i);
}
//cout << nwn << " " << i << " " << X[{nwn, i}] << endl;
nwn = nwn-X[{nwn, i}]*(i*i);
i--;
}
sort(Z.begin(), Z.end());
char next = '0';
deque<int> Zp;
for(int j = 0; Z.size() > j; j++){
if(Z[j]%2 == 1){
zig(Z[j], next);
}else{
Zp.push_back(Z[j]);
}
}
bool back = true;
while(Zp.size()){
if(back){
auto z = Zp.back();Zp.pop_back();
zig(z, '0');
}else{
auto z = Zp.front();Zp.pop_front();
zig(z, '1');
}
back ^= 1;
}
cout << endl;
return 0;
}