QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#357835#7932. AND-OR closureec1117WA 1ms3636kbC++142.6kb2024-03-19 13:38:472024-03-19 13:38:48

Judging History

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

  • [2024-03-19 13:38:48]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3636kb
  • [2024-03-19 13:38:47]
  • 提交

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) // TO LOOK
			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: 100
Accepted
time: 1ms
memory: 3632kb

input:

4
0 1 3 5

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

5
0 1 2 3 4

output:

8

result:

ok 1 number(s): "8"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3636kb

input:

49
1097363587067 1096810445814 275012137504 1096739142630 1096809921522 1087071335264 829364908576 949625500192 1087142638448 1096200190829 1097292808175 1095750860656 1087144145776 1097346808827 1095734082416 1096755396578 829230678048 1095663303524 1087072842592 1096216444777 949623992864 10962714...

output:

16

result:

wrong answer 1st numbers differ - expected: '52', found: '16'