Submission #3601563


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
#define maxn 600020
#define rep(i,l,r) for(register int i = l ; i <= r ; i++)
#define repd(i,r,l) for(register int i = r ; i >= l ; i--)
#define rvc(i,S) for(register int i = 0 ; i < (int)S.size() ; i++)
#define rvcd(i,S) for(register int i = ((int)S.size()) - 1 ; i >= 0 ; i--)
#define fore(i,x)for (register int i = head[x] ; i ; i = e[i].next)
#define pb push_back
#define prev prev_
#define stack stack_
#define mp make_pair
#define fi first
#define se second
#define inf 0x3f3f3f3f
typedef long long ll;
typedef pair<int,int> pr;

int a[maxn],f[maxn],g[maxn];
int n,S;

int main(){
	scanf("%d",&n);
	S = (1 << n) - 1;
	rep(i,0,S) scanf("%d",&f[i]) , g[i] = -inf;
	rep(i,0,n - 1){
		rep(j,0,S){
			if ( j & (1 << i) ){
				if ( f[j] < f[j ^ (1 << i)] ){
					g[j] = f[j] , f[j] = f[j ^ (1 << i)];
					if ( g[j] < g[j ^ (1 << i)] ) g[j] = g[j ^ (1 << i)];
				}
				else if ( g[j] < f[j ^ (1 << i)] ) g[j] = f[j ^ (1 << i)];
			}
		}
	}
/*	rep(j,0,S){
		cout<<j<<" "<<f[j]<<" "<<g[j]<<endl;
	}*/
	rep(i,1,S){
		int pre = 0,ans = f[i] + g[i];
		repd(j,n - 1,0){
			if ( i & (1 << j) ){
				ans = max(ans,f[pre | ((1 << j) - 1)] + g[pre | ((1 << j) - 1)]);
				pre |= 1 << j;
			}
		}
		printf("%d\n",ans);
	}
}

Submission Info

Submission Time
Task E - Or Plus Max
User zhangqingqi
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1309 Byte
Status AC
Exec Time 83 ms
Memory 6144 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:23:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
./Main.cpp:25:44: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  rep(i,0,S) scanf("%d",&f[i]) , g[i] = -inf;
                                            ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 3
AC × 35
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All sample_01.txt, sample_02.txt, sample_03.txt, sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt, subtask_1_14.txt, subtask_1_15.txt, subtask_1_16.txt, subtask_1_17.txt, subtask_1_18.txt, subtask_1_19.txt, subtask_1_20.txt, subtask_1_21.txt, subtask_1_22.txt, subtask_1_23.txt, subtask_1_24.txt, subtask_1_25.txt, subtask_1_26.txt, subtask_1_27.txt, subtask_1_28.txt, subtask_1_29.txt
Case Name Status Exec Time Memory
sample_01.txt AC 2 ms 2304 KB
sample_02.txt AC 2 ms 2304 KB
sample_03.txt AC 2 ms 2304 KB
subtask_1_01.txt AC 2 ms 2304 KB
subtask_1_02.txt AC 2 ms 2304 KB
subtask_1_03.txt AC 10 ms 2560 KB
subtask_1_04.txt AC 2 ms 2304 KB
subtask_1_05.txt AC 2 ms 2304 KB
subtask_1_06.txt AC 4 ms 2432 KB
subtask_1_07.txt AC 4 ms 2432 KB
subtask_1_08.txt AC 2 ms 2304 KB
subtask_1_09.txt AC 2 ms 2304 KB
subtask_1_10.txt AC 6 ms 2432 KB
subtask_1_11.txt AC 2 ms 2304 KB
subtask_1_12.txt AC 10 ms 2816 KB
subtask_1_13.txt AC 2 ms 2304 KB
subtask_1_14.txt AC 83 ms 6144 KB
subtask_1_15.txt AC 2 ms 2304 KB
subtask_1_16.txt AC 83 ms 6144 KB
subtask_1_17.txt AC 71 ms 4608 KB
subtask_1_18.txt AC 70 ms 6016 KB
subtask_1_19.txt AC 70 ms 6144 KB
subtask_1_20.txt AC 80 ms 6144 KB
subtask_1_21.txt AC 83 ms 6144 KB
subtask_1_22.txt AC 83 ms 6144 KB
subtask_1_23.txt AC 83 ms 6144 KB
subtask_1_24.txt AC 72 ms 4608 KB
subtask_1_25.txt AC 70 ms 6016 KB
subtask_1_26.txt AC 70 ms 6144 KB
subtask_1_27.txt AC 81 ms 6144 KB
subtask_1_28.txt AC 83 ms 6144 KB
subtask_1_29.txt AC 83 ms 6144 KB