京都大学プログラミングコンテスト2015

Submission #1770416

Source codeソースコード

#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&1ll<<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

Task問題 H - Bit Count
User nameユーザ名 ixmel
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 300
Source lengthソースコード長 1984 Byte
File nameファイル名
Exec time実行時間 9 ms
Memory usageメモリ使用量 1024 KB

Test case

Set

Set name Score得点 / Max score Cases
All 300 / 300 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
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 AC 8 ms 1024 KB
30_large_05.txt AC 9 ms 1024 KB
30_large_06.txt AC 8 ms 1024 KB
80_power_of_2.txt AC 2 ms 1024 KB