結果
問題 | No.911 ラッキーソート |
ユーザー |
![]() |
提出日時 | 2019-10-19 00:19:08 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,110 ms / 2,000 ms |
コード長 | 2,347 bytes |
コンパイル時間 | 1,898 ms |
コンパイル使用メモリ | 179,576 KB |
実行使用メモリ | 26,320 KB |
最終ジャッジ日時 | 2024-06-25 20:10:20 |
合計ジャッジ時間 | 19,901 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 46 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;using PII = pair<ll, ll>;#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)#define REP(i, n) FOR(i, 0, n)#define ALL(x) x.begin(), x.end()template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;#ifdef DEBUG_#include "../program_contest_library/memo/dump.hpp"#else#define dump(...)#endifconst ll INF = 1LL<<60;int main(void) {ll n, l, r;cin >> n >> l >> r;vector<bitset<64>> a(n);REP(i, n) {ll b;cin >> b;a[i] = bitset<64>(b);}// REP(i, n) cerr << a[i] << endl;vector<vector<ll>> can(62);auto func = [&] {vector<ll> p;REP(i, 62) {ll idx = 0;vector<vector<ll>> v(p.size()+1);REP(j, n) {if(idx<(ll)p.size() && p[idx]==j) idx++;v[idx].push_back(a[j].test(61-i));}// if(i>=40) {dump(i); dump(p); dump(v);}ll sz = 0;bool ok0 = true, ok1 = true;for(auto vec: v) {ll turn = 0;REP(j, vec.size()) {if(turn==0 && vec[j]!=vec[0]) turn = 1, p.push_back(sz+j);else if(turn==1 && vec[j]==vec[0]) {cout << 0 << endl;exit(0);}}if(turn==1) {if(vec[0]==0) ok1 = false;else if(vec[0]==1) ok0 = false;}sz += vec.size();}if(ok0) can[i].push_back(0);if(ok1) can[i].push_back(1);sort(ALL(p));}};auto solve = [&](ll x) -> ll {bitset<64> y(x);vector<vector<ll>> dp(63, vector<ll>(2));dp[0][0] = 1;REP(i, 62) REP(j, 2) {for(auto k: can[i]) {if(j==0 && k > y.test(61-i)) continue;dp[i+1][j || k<y.test(61-i)] += dp[i][j];}}return dp[62][0] + dp[62][1];};func();// dump(can);cout << solve(r) - (l==0?0:solve(l-1)) << endl;return 0;}