Submission #672855
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>inline void chmin(T &t,U f){if(t>f)t=f;} template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;} int N; int dp[61][200][2]; void solve(){ cin>>N; fill_n(**dp,61*200*2,LLONG_MAX); dp[0][100][0]=0; rep(i,60)rep(j,200)rep(k,2){ if(dp[i][j][k]==LLONG_MAX)continue; rep(l,2){ int tmp=N>>i&1; int up=(tmp+k+l)/2; int now=(tmp+k+l)%2; chmin(dp[i+1][j+l-now][up],dp[i][j][k]|(l<<i)); } } if(dp[60][100][0]==LLONG_MAX)cout<<-1<<endl; else cout<<dp[60][100][0]<<endl; } signed main(){ int T;cin>>T; while(T--)solve(); return 0; }
Submission Info
Submission Time | |
---|---|
Task | H - Bit Count |
User | latte0119 |
Language | C++11 (GCC 4.9.2) |
Score | 300 |
Code Size | 1145 Byte |
Status | AC |
Exec Time | 37 ms |
Memory | 1056 KB |
Judge Result
Set Name | All | ||
---|---|---|---|
Score / Max Score | 300 / 300 | ||
Status |
|
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 | 29 ms | 924 KB |
10_small_00.txt | AC | 37 ms | 1048 KB |
20_medium_01.txt | AC | 35 ms | 1048 KB |
20_medium_02.txt | AC | 35 ms | 908 KB |
20_medium_03.txt | AC | 32 ms | 1056 KB |
30_large_04.txt | AC | 35 ms | 924 KB |
30_large_05.txt | AC | 33 ms | 1052 KB |
30_large_06.txt | AC | 35 ms | 932 KB |
80_power_of_2.txt | AC | 26 ms | 992 KB |