結果

問題 No.2067 ±2^k operations
ユーザー 沙耶花沙耶花
提出日時 2022-09-02 22:42:10
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,799 ms / 2,000 ms
コード長 1,564 bytes
コンパイル時間 4,203 ms
コンパイル使用メモリ 260,016 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-10 04:59:30
合計ジャッジ時間 35,724 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 570 ms
4,384 KB
testcase_02 AC 569 ms
4,376 KB
testcase_03 AC 570 ms
4,380 KB
testcase_04 AC 569 ms
4,376 KB
testcase_05 AC 569 ms
4,376 KB
testcase_06 AC 373 ms
4,380 KB
testcase_07 AC 1,768 ms
4,380 KB
testcase_08 AC 1,769 ms
4,380 KB
testcase_09 AC 1,766 ms
4,380 KB
testcase_10 AC 1,763 ms
4,376 KB
testcase_11 AC 1,767 ms
4,380 KB
testcase_12 AC 1,770 ms
4,376 KB
testcase_13 AC 1,768 ms
4,380 KB
testcase_14 AC 1,775 ms
4,380 KB
testcase_15 AC 1,762 ms
4,380 KB
testcase_16 AC 1,765 ms
4,380 KB
testcase_17 AC 1,796 ms
4,380 KB
testcase_18 AC 1,799 ms
4,376 KB
testcase_19 AC 65 ms
4,380 KB
testcase_20 AC 83 ms
4,380 KB
testcase_21 AC 1,762 ms
4,380 KB
testcase_22 AC 1,775 ms
4,380 KB
testcase_23 AC 1,773 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 2000000000000000001

long long dp[2][30][30],ndp[2][30][30];

int main(){
	
	int _t;
	cin>>_t;
	
	rep(_,_t){
		
		long long N;
		cin>>N;
		//N = 1LL << 50;
		//vector dp(2,vector(30,vector<long long>(30,0)));
		rep(j,2){
			rep(k,30){
				rep(l,30){
					dp[j][k][l] = 0;
				}
			}
		}
		dp[0][0][2] = 1;
		bool f = false;
		for(int i=59;i>=0;i--){
			if((N>>i)&1){
				f = true;
			}
			else if(!f)continue;
			rep(j,2){
				rep(k,30){
					rep(l,30){
						ndp[j][k][l] = 0;
					}
				}
			}
			//vector ndp(2,vector(30,vector<long long>(30,0)));
			rep(j,2){
				rep(k,min(30,60-i)){
					rep(l,30){
						if(dp[j][k][l]==0)continue;
						
						rep(m,2){
							int nj = j,nk = 29,nl = 29;
							
							if(j==0 && ((N>>i)&1)==0 && m==1)continue;
							if(((N>>i)&1) && m==0)nj = 1;
							if(m==0){
								nk = min(nk,k);
								nl = min(nl,l+1);
								nk = min(nk,l);
							}
							else{
								nk = min(nk,k+1);
								nl = min(nl,l);
								nl = min(nl,k+2);
							}
							
							ndp[nj][nk][nl] += dp[j][k][l];
						}
						
						
					}
				}
			}
			swap(dp,ndp);
			
		}
		
		long long ans = 0;
		rep(i,2){
			rep(j,30){
				rep(k,30){
					//if(dp[i][j][k])cout<<i<<','<<j<<','<<k<<endl;
					
					ans += dp[i][j][k] * (long long) min(j,k);
				}
			}
		}
		
		cout<<ans<<endl;
		
	}
	
    return 0;
}
0