Submission #1770214


Source Code Expand

#include<bits/stdc++.h>
using namespace std;

#define int long long

typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

int b=150;
int dp[66][333][2];
void solve(){
    int latte;cin>>latte;
    string s;

    rep(i,60)s+=(latte>>i&1)+'0';

    fill_n(**dp,66*333*2,LLONG_MAX);
    dp[0][b][0]=0;

    rep(i,60){
        for(int j=-60;j<=60;j++){
            rep(k,2){
                if(dp[i][j+b][k]==LLONG_MAX)continue;
                rep(l,2){
                    int n=(k+l+s[i]-'0')%2;
                    chmin(dp[i+1][j+b+n-l][(k+l+s[i]-'0')>=2],dp[i][j+b][k]+(l<<i));
                }
            }
        }
    }

    cout<<dp[60][b][0]<<endl;
}

signed main(){
    int T;cin>>T;
    while(T--)solve();
}

Submission Info

Submission Time
Task H - Bit Count
User latte0119
Language C++14 (GCC 5.4.1)
Score 300
Code Size 1193 Byte
Status AC
Exec Time 9 ms
Memory 640 KB

Judge Result

Set Name All
Score / Max Score 300 / 300
Status
AC × 9
Set Name Test Cases
All 00_sample.txt, 10_small_00.txt, 20_medium_01.txt, 20_medium_02.txt, 20_medium_03.txt, 30_large_04.txt, 30_large_05.txt, 30_large_06.txt, 80_power_of_2.txt
Case Name Status Exec Time Memory
00_sample.txt AC 2 ms 640 KB
10_small_00.txt AC 7 ms 640 KB
20_medium_01.txt AC 7 ms 640 KB
20_medium_02.txt AC 8 ms 640 KB
20_medium_03.txt AC 7 ms 640 KB
30_large_04.txt AC 8 ms 640 KB
30_large_05.txt AC 9 ms 640 KB
30_large_06.txt AC 8 ms 640 KB
80_power_of_2.txt AC 2 ms 640 KB