QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#706734#8332. Two in OneAnneliese#RE 0ms0kbC++141.7kb2024-11-03 13:10:502024-11-03 13:10:51

Judging History

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

  • [2024-11-03 13:10:51]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-03 13:10:50]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
using LL = long long;
using ll = long long;
const int N = 100005;
#define rep(i,a ,b )  for(int i = a ;i<=b;i++)
#define pre(i,a ,b )  for(int i = a ;i>=b;i--)
#define pb push_back
#define sc(x) scanf("%d",&x)

const int mod=1e9+9;
ll hz[25];
ll get(ll x,ll y){
	int fg=0;ll res=0;
	pre(i,20,0){
		int u=0,v=0;
		if(x&(1<<i)){
			u=1;
		}
		if(y&(1<<i)){
			v=1;
		}
		if(!u&&!v)continue;
		//cout<<i<<" "<<u<<" "<<v<<endl;
		if(u==v){
			res|=hz[i];
			return res;
		}
		else{
			res|=(1<<i);
		}
	}
	return res;
}
int cnt[N];
void solve() {
	int n;
	sc(n);
	rep(i,1,n)cnt[i]=0;vector<int>p[25];
	rep(i,1,n){
		int x;sc(x);cnt[x]++;
	}
	rep(i,1,n){
		int nw=0;if(!cnt[i])continue;
		int x=cnt[i];
		rep(j,0,20){
			if(((1<<j)&x)){
				nw=j;
			}
		}
		p[nw].pb(x);
	}
	ll res=0;
	pre(i,20,0){
		if(!p[i].size())continue;
		if(p[i].size()>1){
		//	cout<<hz[i]<<" "<<i<<endl;
			res=hz[i];
			break;
		//	printf("%lld\n",hz[i]);
		}
		else{
			int fg=0,ne=0;
		//	cout<<p[1].size()<<" "<<i<<endl;
			pre(j,i-1,0){
				if(p[j].size()){
					fg=1;ne=j;
				}	
			}
			//cout<<ne<<" "<<p[ne].size()<<" "<<fg<<endl;
			if(!fg){
				res=p[i][0];
			//	break;
				//printf("%lld\n",p[i][0]);
			}
			else{
				rep(j,0,p[ne].size()-1){
				//	cout<<p[ne][j]<<" "<<p[i][0]<<endl;
					res=max(res,get(p[i][0],p[ne][j]));
				}
			}
			break;
		}
	}
	printf("%lld\n",res);
}


int main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    hz[0]=1;
	rep(i,1,20){
		hz[i]=(hz[i-1]|(1<<i));
	}
    int t = 1;
    cin >> t ;

    while (t--) {
        solve();
    }

    return 0;


}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

1
7
1 2 3 4 3 2 1

output:


result: