結果

問題 No.2071 Shift and OR
ユーザー Wex OneWex One
提出日時 2022-09-16 22:16:33
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,061 bytes
コンパイル時間 1,145 ms
コンパイル使用メモリ 106,800 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 15:56:15
合計ジャッジ時間 10,029 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 32 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 403 ms
4,376 KB
testcase_12 AC 14 ms
4,380 KB
testcase_13 AC 128 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 40 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 TLE -
testcase_20 AC 1,000 ms
4,380 KB
testcase_21 TLE -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<string>
#include<set>
#include<algorithm>
#include<cmath>
#include<limits>
#include<iomanip>
// #include<atcoder/all>
using namespace std;
// using namespace atcoder;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll, ll>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>

const int MOD = 1e9+7;
const int MOD2 = 998244353;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double eps = 1e-6;

template <typename T>
bool PN(T x){ if (x <= 1) return false; if (x == 2) return true; for (int i = 2; i < sqrt(x) + 1; i++) if (x % i == 0) return false; return true;}
long long Comb(int n, int i){long long ans = 1; if(i>n || i < 0) return 0; if(i == 0 || i == n) return 1; else {for(int j = 1; j <= i; ++j){ans *=(n+1-j); ans /= j; ans %= MOD;} }return ans;}
template<typename T> T gcd(T a, T b){if(b == 0) return a;else return gcd(b, a%b);}
template<typename T> T lcm(T a, T b){if(b > a) swap(a, b); T g = gcd(a, b);return a / g * b;}

template<class T> T modpow(T a, T b, T m) {
	// a^b mod m を求める
	long long p = 1, q = a;
	for (int i = 0; i < 30; i++) {
		if ((b & (1LL << i)) != 0) {
			p *= q; p %= m;
		}
		q *= q; q %= m;
	}
	return p;
}

template<class T> T Div(T a, T b, T m) {
	// a÷b の mod m での逆元を求める
	return (a * modpow(b, m - 2, m)) % m;
}

priority_queue<pii, vector<pii>, greater<pii>> pq;

void show_bit(int x) {
	string ret = "";
	while(x) {
		if(x & 1) ret  = "1" + ret;
		else ret = "0" + ret;
		x >>= 1;
	}
	cout << ret << endl;
}

int shift(int x){
	return x/2+(1<<15)*(x%2);
}

void solve() {
	int n; cin >> n;
	vector<int> a(n);
	int num_bit = 0;
	if(n >= 16) {
		cout << (1 << 16) - 1 << endl;
		return;
	}
	rep(i, n) cin >> a[i];
	vector<int> cnt(n, 0);
	vector<int> val(n, 0);
	int total_bit = 0;
	for(int i = 0; i < n; i++) {
		int tmp = a[i];
		int cont_max = 0;
		int cont = 0;
		for(int j = 0; j < 16; j++) {
			tmp = shift(tmp);
			val[i] = max(val[i], tmp);
			if(tmp&1) {
				cont++;
				cont_max = max(cont_max, cont);
			} else {
				cont = 0;
			}
		}
		// show_bit(val[i]);
		total_bit += cont;
		cnt[i] = cont;
	}
	sort(cnt.rbegin(), cnt.rend());
	sort(val.begin(), val.end());
	int ans = 0;
	const int MAX = (1 << total_bit) - 1;
	do {
		int ans_tmp = 0;
		for(int i = 0; i < n; i ++) {
			for(int j = 15; j >= 0; j--) {
				if(((ans_tmp >> j) & 1) == 0) {
					// cerr << j << " " << ans_tmp << endl;
					int sh = val[i];
					for(int k = 0; k < 15-j; k++) {
						sh = shift(sh);
					}
					ans_tmp |= sh;
					break;
				}
			}
		}
		if(ans_tmp == MAX) {
			cerr << "YES" << endl;
			cout << ans << endl;
			return ;
		}
		// cerr << "ans tmp: " << ans_tmp << endl;
		ans = max(ans, ans_tmp);
	} while(next_permutation(val.begin(), val.end()));

	cout << ans << endl;
}

int main(void){
  solve();
  return 0;
}
0