結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー roundplusroundplus
提出日時 2019-09-26 00:08:03
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 314 ms / 2,000 ms
コード長 2,738 bytes
コンパイル時間 1,815 ms
コンパイル使用メモリ 102,984 KB
実行使用メモリ 6,552 KB
最終ジャッジ日時 2023-09-02 07:12:25
合計ジャッジ時間 5,557 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
5,212 KB
testcase_01 AC 72 ms
4,416 KB
testcase_02 AC 299 ms
6,504 KB
testcase_03 AC 244 ms
6,068 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 64 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 18 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 10 ms
4,380 KB
testcase_33 AC 3 ms
4,376 KB
testcase_34 AC 40 ms
4,376 KB
testcase_35 AC 312 ms
6,552 KB
testcase_36 AC 162 ms
5,468 KB
testcase_37 AC 314 ms
6,504 KB
testcase_38 AC 310 ms
6,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
#include <numeric>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define BOUND 27182818284
#define MAT 2

typedef long long ll;
typedef long long int lli;
typedef pair<ll, ll> P;

ll MOD = 1000000007;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for(int i=int(a);i<int(b);++i)

template<class T>
bool umax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// gcd
template<typename T>
T gcd(T a, T b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int findGCD(int arr[], int n) {
    int result = arr[0];
    for (int i = 1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm(T m, T n) {
    // 引数に0がある場合は0を返す
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    fill((T *) array, (T *) (array + N), val);
}


int dx[5] = {1, 0, -1, 0};
int dy[5] = {0, 1, 0, -1};

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};

ll priority(ll a){
    if(a&1){ // 奇数
        return a;
    }else{
        return INFint-a;
    }
}

int main() {
    int N; cin >> N;

    vector<int> cost(N+1,INFint),
                minimum(N+1, INFint),
                maximum(N+1, -INFint);
    cost[0]=0;
    for(int i=1; i<=N; i++){
        for(int j=1; j*j<=i; j++){
            if(cost[i]>cost[i-j*j]+j){
                cost[i]=cost[i-j*j]+j;
                minimum[i]=j;
                maximum[i]=j;
            }else if(cost[i]==cost[i-j*j]+j){
                if(priority(minimum[i])>priority(j))
                    minimum[i]=j;
                if(priority(maximum[i])<priority(j))
                    maximum[i]=j;
            }
        }
    }


    int c=0;

    while(N){
        int cnt;
        if(c==1){
            cnt=maximum[N];
        }else{
            cnt=minimum[N];
        }
        N-=cnt*cnt;

        for(ll i=0; i<cnt; i++){
            cout << c;
            c^=1;
        }
        c^=1;
    }

    cout << endl;
    return 0;
}
0