Submission #1770410


Source Code Expand

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
ll dp[400][120][2];
int MOD=1000000007;
ll f(ll a){
	int n;
	rep(i,60)if(a&1ll<<(60-i-1)){
		n=60-i+1;
		break;
	}
	//syokika
	rep(i,400)rep(j,120)rep(k,2)dp[i][j][k]=inf;
	dp[0][60][0]=0;
	rep(i,n)rep(j,120)rep(k,2)rep(x,2)if(dp[i][j][k]!=inf){
		int I=i+1,J=j;
		if(x)J++;
		int t=x+k;
		if(a&1<<i)t++;
		if(t%2)J--;
		int K=t/2;
		ll q=dp[i][j][k];
		if(x)q+=1ll<<i;
		dp[I][J][K]=min(dp[I][J][K],q);
	}
	ll mi=inf;
	rep(k,2)mi=min(mi,dp[n][60][0]);
	return mi;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		ll a;cin>>a;
		cout<<f(a)<<endl;
	}
}





Submission Info

Submission Time
Task H - Bit Count
User ixmel_rd
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1982 Byte
Status WA
Exec Time 9 ms
Memory 1024 KB

Judge Result

Set Name All
Score / Max Score 0 / 300
Status
AC × 5
WA × 4
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 1024 KB
10_small_00.txt AC 6 ms 1024 KB
20_medium_01.txt AC 6 ms 1024 KB
20_medium_02.txt AC 7 ms 1024 KB
20_medium_03.txt AC 6 ms 1024 KB
30_large_04.txt WA 8 ms 1024 KB
30_large_05.txt WA 9 ms 1024 KB
30_large_06.txt WA 8 ms 1024 KB
80_power_of_2.txt WA 2 ms 1024 KB