結果
問題 |
No.911 ラッキーソート
|
ユーザー |
![]() |
提出日時 | 2020-02-03 08:56:23 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 206 ms / 2,000 ms |
コード長 | 2,737 bytes |
コンパイル時間 | 1,129 ms |
コンパイル使用メモリ | 109,612 KB |
実行使用メモリ | 14,336 KB |
最終ジャッジ日時 | 2024-09-18 21:38:49 |
合計ジャッジ時間 | 7,298 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 46 |
ソースコード
#include<iostream> #include<string> #include<cstdio> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> #include<complex> #include<bitset> #include<stack> #include<unordered_map> #include<utility> #include<tuple> using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 1000000007; const ll INF = (ll)1000000007 * 1000000007; typedef pair<int, int> P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define Per(i,sta,n) for(int i=n-1;i>=sta;i--) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) typedef long double ld; typedef complex<ld> Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<ll, ll> LP; int n,x[62]; ll L,R,a[200010],dp[62][2][2]; bool l[62],r[62]; ll rec(int k,int flagL,int flagR){ if(k==-1) return 1; if(dp[k][flagL][flagR]!=-1) return dp[k][flagL][flagR]; ll res=0; // 1 if(x[k]!=0 && (flagR || r[k]==1)) res+=rec(k-1,flagL||(l[k]==0),flagR); // 0 if(x[k]!=1 && (flagL || l[k]==0)) res+=rec(k-1,flagL,flagR||(r[k]==1)); dp[k][flagL][flagR]=res; //cout << k << " " << flagL << " " << flagR << " " << res << endl; return res; } void solve(){ cin >> n >> L >> R; rep(k,62){ l[k]=(L & (1ll << k)); r[k]=(R & (1ll << k)); //cout << l[k] << " " << r[k] << endl; rep(flagL,2){ rep(flagR,2){ dp[k][flagL][flagR]=-1; } } } rep(i,n){ cin >> a[i]; } per(k,62){ x[k]=-1; } set<int> se{0,n}; per(k,62){ bool first,changed=false; auto idx=se.begin(); vector<int> v={}; //cout << k << endl; rep(i,n){ bool b=(a[i]&(1ll << k)); //cout << b << " "; if (*idx==i) { first=b; idx++; changed=false; continue; } bool pre_b=(a[i-1]&(1ll << k)); if (pre_b!=b){ v.push_back(i); if(changed) { cout << 0 << endl; return; } else{ changed=true; int s=pre_b; if(x[k]==-1 || x[k]==s){ x[k]=s; } else { cout << 0 << endl; return; } } } } for(int v_:v){ se.insert(v_); //cout << v_ << " "; } //cout << "" << endl; } per(i,62){ //cout << x[i] << " "; } //cout << "" << endl; cout << rec(61,0,0) << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(50); solve(); }