题解:P15867 【MX-X26-T3】「Cfz Round 7」GLACIES
Solution
操作相当于可以将某一个数左移一位,超过
那么最大“鱼鱼值”相当于把
我们贪心的取高位,即尝试将当前的鱼鱼值
复杂度
Code
// Code By CommandSR (uid 844860)
const int N = 5e5 + 5;
int n, m, a[N];
bool check(int y) {
F(i, 1, n) {
int x = a[i];
bool flag = 0;
F(j, 1, m) {
if ((x & y) == y) {
flag = 1;
break;
}
x <<= 1;
}
if (!flag) return 0;
}
return 1;
}
int calc(int y) {
int ans = 0;
F(i, 1, n) {
int x = a[i];
F(j, 0, m) {
if ((x & y) == y) {
ans += j;
break;
}
x <<= 1;
}
}
return ans;
}
void sol() {
cin >> n >> m;
F(i, 1, n) cin >> a[i];
int ans = 0;
D(i, m-1, 0) if (check(ans | (1ll<<i))) ans |= (1ll<<i);
cout << calc(ans) << '\n';
}