QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#357830#7932. AND-OR closureec1117WA 0ms3488kbC++142.5kb2024-03-19 13:27:512024-03-19 13:27:52

Judging History

你现在查看的是最新测评结果

  • [2024-03-19 13:27:52]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3488kb
  • [2024-03-19 13:27:51]
  • 提交

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];
		For(k,40) if(a[i] & (1LL<<k)) {
			has[k].pb(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,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
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3488kb

input:

4
0 1 3 5

output:

6

result:

wrong answer 1st numbers differ - expected: '5', found: '6'