結果

問題 No.2918 Divide Applicants Fairly
ユーザー 👑 kmjpkmjp
提出日時 2024-10-07 22:58:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,988 bytes
コンパイル時間 2,282 ms
コンパイル使用メモリ 208,828 KB
実行使用メモリ 12,936 KB
最終ジャッジ日時 2024-10-07 22:58:45
合計ジャッジ時間 4,963 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,248 KB
testcase_04 AC 2 ms
5,248 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
5,248 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
5,248 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1 ms
5,248 KB
testcase_16 AC 2 ms
5,248 KB
testcase_17 WA -
testcase_18 AC 110 ms
8,956 KB
testcase_19 AC 2 ms
5,248 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2 ms
5,248 KB
testcase_23 WA -
testcase_24 AC 2 ms
5,248 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 2 ms
5,248 KB
testcase_31 WA -
testcase_32 AC 2 ms
5,248 KB
testcase_33 AC 2 ms
5,248 KB
testcase_34 AC 2 ms
5,248 KB
testcase_35 AC 2 ms
5,248 KB
testcase_36 AC 34 ms
5,248 KB
testcase_37 AC 19 ms
5,248 KB
testcase_38 AC 10 ms
5,248 KB
testcase_39 AC 2 ms
5,248 KB
testcase_40 AC 5 ms
5,248 KB
testcase_41 AC 9 ms
5,248 KB
testcase_42 AC 13 ms
5,248 KB
testcase_43 AC 24 ms
6,848 KB
testcase_44 AC 39 ms
8,932 KB
testcase_45 AC 74 ms
12,932 KB
testcase_46 AC 2 ms
5,248 KB
testcase_47 AC 2 ms
5,248 KB
testcase_48 WA -
testcase_49 AC 18 ms
5,248 KB
testcase_50 AC 2 ms
5,248 KB
testcase_51 AC 4 ms
5,248 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 AC 5 ms
5,248 KB
testcase_55 AC 8 ms
5,248 KB
testcase_56 AC 8 ms
5,248 KB
testcase_57 WA -
testcase_58 AC 7 ms
5,248 KB
testcase_59 AC 7 ms
5,248 KB
testcase_60 WA -
testcase_61 AC 8 ms
5,248 KB
testcase_62 WA -
testcase_63 AC 3 ms
5,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------


int N;
int R[44];

vector<int> V[2][15];
vector<int> W[2][15];

void dfs(int cur,int vis,int num,int rate) {
	if(cur>=N/2) {
		if(num<0) num=-num,rate=-rate;
		V[vis][num].push_back(rate);
		return;
	}
	dfs(cur+1,1,num+1,rate+R[cur]);
	dfs(cur+1,vis,num,rate);
	dfs(cur+1,1,num-1,rate-R[cur]);
}
void dfs2(int cur,int vis,int num,int rate) {
	if(cur<N/2) {
		if(num<0) num=-num,rate=-rate;
		W[vis][num].push_back(rate);
		return;
	}
	dfs2(cur-1,1,num+1,rate+R[cur]);
	dfs2(cur-1,vis,num,rate);
	dfs2(cur-1,1,num-1,rate-R[cur]);
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>R[i];
	
	if(N>=26) {
		cout<<0<<endl;
		return;
	}
	
	dfs(0,0,0,0);
	dfs2(N-1,0,0,0);
	int ret=1<<30;
	int a,b;
	FOR(i,15) {
		FOR(a,2) FOR(b,2) if(a+b>0) {
			sort(ALL(V[a][i]));
			sort(ALL(W[b][i]));
			W[b][i].erase(unique(ALL(W[b][i])),W[b][i].end());
			if(V[a][i].empty()||W[b][i].empty()) continue;
			x=W[b][i].size()-1;
			FORR(v,V[a][i]) {
				while(x>0&&abs(v-W[b][i][x-1])<abs(v-W[b][i][x])) x--;
				ret=min(ret,abs(v-W[b][i][x]));
				if(x) ret=min(ret,abs(v-W[b][i][x-1]));
				if(x+1<W[b][i].size()) ret=min(ret,abs(v-W[b][i][x+1]));
			}
		}
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0