QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#357833 | #7932. AND-OR closure | ec1117 | RE | 0ms | 3664kb | C++14 | 2.6kb | 2024-03-19 13:34:45 | 2024-03-19 13:34:45 |
Judging History
answer
#include <bits/stdc++.h>
#include <random>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
#define mp make_pair
#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize
#define bk back()
#define pb push_back
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define For(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define Rof(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
const int MOD = 1e9+7;
const ld PI = acos((ld)-1);
mt19937 rng; // or mt19937_64
template<class T> bool ckmin(T& a, const T& b) {
return b < a ? a = b, 1 : 0; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
cerr << h; if (sizeof...(t)) cerr << ", ";
DBG(t...); }
#ifdef LOCAL // compile with -DLOCAL
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif
const int MX2 = 41;
vl has[MX2], has2[MX2];
ll rep2[MX2];
int sz[MX2];
vi todo[MX2];
ll ways[45];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n;cin>>n;
vl a(n);
ways[40]=1;
For(i,n) {
cin>>a[i];
}
if(a[0]==0 && n==1) {
cout << 1 << '\n';
return 0;
}
int tot = (a[0]==0)?a[1]:a[0];
bool hasZero = false;
For(i,n) {
if(a[i])
tot &= a[i];
else
hasZero = true;
}
For(i,n) {
if(a[i]) {
a[i] -= tot;
}
}
For(i,n) {
For(k,40) if(a[i] & (1LL<<k)) {
has[k].pb(a[i]);
}
}
For(i,40) if(has[i].size()) {
ways[i] = 1;
rep2[i] = has[i][0];
if(tot)
has2[i].pb(0);
trav(x,has[i]) {
rep2[i] &= x;
}
For(j,40)if(rep2[i] & (1LL<<j)) {
dbg(i,j);
has2[i].pb(j);
sz[i]++;
}
todo[sz[i]].pb(i);
}
Rof(i, MX2) {
vector<bool> done(45);
trav(x,todo[i]) if(!done[x]) {
pi par = {0,40};
trav(y,has2[x]) {
done[y] = true;
if (sz[y] < sz[x]) {
par = max(par, {sz[y], y});
} else {
assert(sz[y]==sz[x]);
}
}
dbg(par.f,par.s,x,ways[x]);
ways[par.s] *= (1+ways[x]);
dbg("AF",ways[par.s]);
}
}
ll ans = 0;
For(i,43) {
ans = max(ans, ways[i]);
}
dbg(tot, hasZero,ans);
if(tot!=0 && hasZero) {
ans++;
}
cout << ans << '\n';
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3568kb
input:
4 0 1 3 5
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
5 0 1 2 3 4
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: -100
Runtime Error
input:
49 1097363587067 1096810445814 275012137504 1096739142630 1096809921522 1087071335264 829364908576 949625500192 1087142638448 1096200190829 1097292808175 1095750860656 1087144145776 1097346808827 1095734082416 1096755396578 829230678048 1095663303524 1087072842592 1096216444777 949623992864 10962714...