結果
問題 | No.2067 ±2^k operations |
ユーザー |
|
提出日時 | 2022-09-14 15:15:39 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 2,900 bytes |
コンパイル時間 | 3,449 ms |
コンパイル使用メモリ | 188,176 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-15 02:51:53 |
合計ジャッジ時間 | 5,410 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 23 |
ソースコード
#include<bits/stdc++.h>using namespace std;#define ll long long#define lll long long//__int128#define pii pair<int,int>//#define f first#define s second# define pi 3.14159265358979323846#include <ext/pb_ds/assoc_container.hpp>using namespace __gnu_pbds;struct chash_key{ll operator()(pii x) const { return (ll)x.first*1000000000 + x.second; }};//gp_hash_table<pii,int,chash_key> hs[2],p[2];//gp_hash_table<ll,int> dp;/*ios_base::sync_with_stdio(false);cin.tie(0),cout.tie(0);cout << fixed;cout.precision(3);cout << x << '\n';*/struct P{int x,y,z;bool operator <(const P &a)const{return y>a.y;};};int a,b,c;int o[66];ll dp[60][2][2],one=1,y;ll f(int n,int c,int d){if(n<0){return 0;}if(dp[n][c][d]>=0) return dp[n][c][d];ll x=0;if(!d){if(!o[n]){if(n==0) x=0;else if(c==0) x=f(n-1,0,0);else if(o[n-1]==1){x+=f(n-2,0,1);x+=f(n-2,1,0)+(((one<<(n-1))-1)&y)+1;}else{x=f(n-2,0,0);}}else if(c==0){x=f(n-1,c,1);if(n==0) x+=f(n-1,0,0)+1;else if(o[n-1]==1){x+=f(n-2,0,1)+(one<<(n-1));/*if(y==13){cout<<(((one<<(n-1))-1)&y)*2+2<<"##\n";}if(y==12){cout<<(((one<<(n-1))-1)&y)*2+2<<"##\n";}*/x+=f(n-2,1,0)+(((one<<(n-1))-1)&y)*2+2;}else{x+=f(n-2,0,0)+(((one<<(n-1))-1)&y)+1;}}else{x=f(n-1,1,0);if(n==0) x+=f(n-1,0,0);else{x+=f(n-2,1,1)+(one<<(n-1));x+=f(n-2,0,1);}}}else{if(c==0){x=f(n-1,c,1);if(n==0) x+=f(n-1,0,0)+1;else{x+=f(n-2,0,1)+(one<<(n-1));x+=f(n-2,1,1)+(one<<(n-1))*2;}}else{x=f(n-1,1,1);if(n==0) x+=f(n-1,0,0);else{x+=f(n-2,1,1)+(one<<(n-1));x+=f(n-2,0,1);}}}return dp[n][c][d]=x;}int main(){ios_base::sync_with_stdio(false);cin.tie(0),cout.tie(0);int ttt=100;cin>>ttt;for(int tt=1;tt<=ttt;tt++){memset(dp,-1,sizeof(dp));cin>>y;//y=tt;for(int i=0;i<60;i++){if(y&(one<<i)) o[i]=1;else o[i]=0;}cout<<f(59,0,0)<<"\n";}}//13 14//1101