結果

問題 No.332 数列をプレゼントに
ユーザー bal4ubal4u
提出日時 2019-07-08 14:11:49
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,958 bytes
コンパイル時間 365 ms
コンパイル使用メモリ 32,768 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 01:24:42
合計ジャッジ時間 1,932 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 6 ms
5,376 KB
testcase_19 AC 4 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 1 ms
5,376 KB
testcase_34 AC 1 ms
5,376 KB
testcase_35 AC 1 ms
5,376 KB
testcase_36 AC 1 ms
5,376 KB
testcase_37 AC 1 ms
5,376 KB
testcase_38 AC 1 ms
5,376 KB
testcase_39 AC 1 ms
5,376 KB
testcase_40 AC 1 ms
5,376 KB
testcase_41 AC 1 ms
5,376 KB
testcase_42 AC 1 ms
5,376 KB
testcase_43 AC 1 ms
5,376 KB
testcase_44 AC 1 ms
5,376 KB
testcase_45 AC 1 ms
5,376 KB
testcase_46 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'in':
main.c:10:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
   10 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:18:27: note: in expansion of macro 'gc'
   18 |         ll n = 0; int c = gc();
      |                           ^~
main.c: In function 'outs':
main.c:11:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration]
   11 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:23:33: note: in expansion of macro 'pc'
   23 | void outs(char *s) { while (*s) pc(*s++); pc('\n'); }
      |                                 ^~

ソースコード

diff #

// yukicoder: No.332 数列をプレゼントに
// 2019.7.8 bal4u

#include <stdio.h>
#include <stdlib.h>

typedef long long ll;

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

ll in() {   // 非負整数の入力
	ll n = 0; int c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void outs(char *s) { while (*s) pc(*s++); pc('\n'); }
void outc(int f, char c) { while (f--) pc(c); pc('\n'); }

#define LIM 99990 // 100000

typedef struct { int v, id; } T;
T a[105], b[105]; int fa, fb; int N; ll X;
char f[105];
int dp[80*LIM];

int cmp(const void *a, const void *b) { return ((T *)a)->v - ((T *)b)->v; }

void final(int p, int q) {
	int i;

	while (p) {
		f[(dp[p] & 127)-1] = 1;
		p = dp[p] >> 7;
	}
	for (i = 0; q; i++) {
		if (q & 1) f[b[i].id] = 1;
		q >>= 1;
	}
	for (i = 0; i < N; i++) pc(f[i]? 'o': 'x');	pc('\n');
	exit(0);
}

int main()
{
	int i, j, x, ma;
	ll s, sb;
	
	N = (int)in(), X = in(), s = sb = 0, fa = 1, fb = 0;
	for (i = 0; i < N; i++) {
		x = (int)in(), s += x;
		if (x <= LIM) a[++fa].id = i, a[fa].v = x;
		else b[fb].id = i, b[fb++].v = x, sb += x;
	}
	if (s == X) { outc(N, 'o'); return 0; }
	if (s < X) { outs("No"); return 0; }
	
	qsort(a+2, fa-1, sizeof(T), cmp);
	qsort(b, fb, sizeof(T), cmp);
	dp[0] = 1, ma = 0;
	for (i = 2; i <= fa; i++) {
		for (j = ma; j >= 0; j--) {
			if (dp[j] && !dp[j+a[i].v]) dp[j+a[i].v] = (j << 7) | (a[i].id+1);
		}
		ma += a[i].v;
	}
//	printf("ma=%d, fa=%d, fb=%d, X=%lld, s=%lld, X-s=%lld\n", ma, fa-1, fb, X, s, s-X);
	if (X <= ma && dp[X]) final(X, 0);
	if (X >= sb && X-sb <= ma && dp[X-sb]) final(X-sb, (1<<fb)-1);
	
	i = 1 << fb; while (--i) {
		s = 0, x = i;
		for (j = 0; x; j++) {
			if (x & 1) {
				s += b[j].v;
				if (s > X) goto next;
			}
			x >>= 1;
		}
		if ((s << 1) < X-ma) break;
		if (X-s <= ma && dp[X-s]) final(X-s, i);
next:;
	}
	outs("No");
	return 0;
}
0