結果

問題 No.332 数列をプレゼントに
ユーザー FF256grhyFF256grhy
提出日時 2015-12-25 13:14:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 1,721 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 27,840 KB
実行使用メモリ 13,312 KB
最終ジャッジ日時 2023-08-25 21:15:06
合計ジャッジ時間 2,861 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,984 KB
testcase_01 AC 2 ms
4,928 KB
testcase_02 AC 2 ms
4,988 KB
testcase_03 AC 1 ms
4,924 KB
testcase_04 AC 2 ms
4,932 KB
testcase_05 AC 9 ms
13,164 KB
testcase_06 AC 9 ms
13,232 KB
testcase_07 AC 13 ms
13,176 KB
testcase_08 AC 10 ms
13,104 KB
testcase_09 AC 2 ms
5,048 KB
testcase_10 AC 7 ms
13,108 KB
testcase_11 AC 8 ms
13,112 KB
testcase_12 AC 11 ms
13,236 KB
testcase_13 AC 10 ms
13,208 KB
testcase_14 AC 7 ms
13,216 KB
testcase_15 AC 11 ms
13,260 KB
testcase_16 AC 10 ms
13,232 KB
testcase_17 AC 11 ms
13,100 KB
testcase_18 AC 11 ms
13,252 KB
testcase_19 AC 11 ms
13,176 KB
testcase_20 AC 10 ms
13,228 KB
testcase_21 AC 11 ms
13,196 KB
testcase_22 AC 10 ms
13,224 KB
testcase_23 AC 11 ms
13,108 KB
testcase_24 AC 12 ms
13,236 KB
testcase_25 AC 12 ms
13,124 KB
testcase_26 AC 12 ms
13,224 KB
testcase_27 AC 11 ms
13,212 KB
testcase_28 AC 12 ms
13,112 KB
testcase_29 AC 13 ms
13,256 KB
testcase_30 AC 12 ms
13,232 KB
testcase_31 AC 13 ms
13,172 KB
testcase_32 AC 13 ms
13,168 KB
testcase_33 AC 13 ms
13,236 KB
testcase_34 AC 13 ms
13,228 KB
testcase_35 AC 13 ms
13,228 KB
testcase_36 AC 2 ms
4,988 KB
testcase_37 AC 12 ms
13,244 KB
testcase_38 AC 12 ms
13,236 KB
testcase_39 AC 11 ms
13,172 KB
testcase_40 AC 13 ms
13,312 KB
testcase_41 AC 13 ms
13,184 KB
testcase_42 AC 13 ms
13,168 KB
testcase_43 AC 13 ms
13,172 KB
testcase_44 AC 12 ms
13,212 KB
testcase_45 AC 13 ms
13,188 KB
testcase_46 AC 9 ms
13,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

#define SUM 100000

int n, a[100], s_sum[SUM], s_ans[SUM + 1][100], s_c = 1;
long long int x, l_sum[1<<20], l_c;
int b[100], b_copy[100], index_[100], i_copy[100], rank[100];

void sort(int l, int r) {
	if(l == r) { return; }
	
	int m = (l + r) / 2;
	sort(l    , m);
	sort(m + 1, r);
	
	int lc = l, rc = m + 1, cc = l;
	while(cc <= r) {
		if(r < rc || (lc <= m && b[lc] >= b[rc]) ) {
			b_copy[cc] = b[lc];
			i_copy[cc] = index_[lc];
			lc++; cc++;
		} else {
			b_copy[cc] = b[rc];
			i_copy[cc] = index_[rc];
			rc++; cc++;
		}
	}
	
	int i;
	for(i = l; i <= r; i++) {
 		b[i] = b_copy[i];
		index_[i] = i_copy[i];
	}
	
	 return;
}

int main(void) {
	s_sum[0] = s_c;
	s_c++;
	
	scanf("%d%lld", &n, &x);
	
	int i, j, k, l_c = 0;
	for(i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		b[i] = a[i];
		index_[i] = i;
	}
	
	sort(0, n - 1);
	for(i = 0; i < n; i++) {
		rank[ index_[i] ] = i;
	}
	
	for(i = 0; i < n; i++) {
		if(20 <= rank[i]) {
			for(j = SUM - 1; 0 <= j; j--) {
				if(s_sum[j] != 0 && s_sum[ j + a[i] ] == 0) {
					for(k = 0; k < i; k++) {
						s_ans[s_c][k] = s_ans[ s_sum[j] ][k];
					}
					s_ans[s_c][i] = 1;
					s_sum[ j + a[i] ] = s_c;
					s_c++;
				}
			}
		} else {
			for(j = 0; j < (1 << l_c); j++) {
				l_sum[ j + (1 << l_c) ] = l_sum[j] + a[i];
			}
			l_c++;
		}
	}
	
	int flag = 0;
	for(j = 0; j < (1 << l_c); j++) {
		long long int v = x - l_sum[j];
		if(0 <= v && v < SUM && s_sum[v] != 0) {
			flag = 1;
			for(i = 0; i < n; i++) {
				if(20 <= rank[i]) {
					printf("%c", s_ans[ s_sum[v] ][i] ? 'o' : 'x');
				} else {
					printf("%c", j % 2 ? 'o' : 'x');
					j /= 2;
				}
			}
			printf("\n");
			break;
		}
	}
	
	if(! flag) { printf("No\n"); }
	
	return 0;
}
0