結果

問題 No.332 数列をプレゼントに
ユーザー bal4ubal4u
提出日時 2019-07-08 08:28:50
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,777 bytes
コンパイル時間 445 ms
コンパイル使用メモリ 32,384 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 18:26:35
合計ジャッジ時間 3,772 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 8 ms
5,376 KB
testcase_06 WA -
testcase_07 AC 14 ms
5,376 KB
testcase_08 WA -
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 9 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 19 ms
5,376 KB
testcase_19 WA -
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 WA -
testcase_24 AC 9 ms
5,376 KB
testcase_25 AC 8 ms
5,376 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 5 ms
5,376 KB
testcase_29 AC 6 ms
5,376 KB
testcase_30 WA -
testcase_31 AC 4 ms
5,376 KB
testcase_32 AC 4 ms
5,376 KB
testcase_33 AC 4 ms
5,376 KB
testcase_34 AC 16 ms
5,376 KB
testcase_35 AC 54 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 8 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 100000
int N; ll X;
int a[102], b[102]; int fa, fb;
int dp[80*LIM];

char f[102];
void final(int p, int q) {
	int i;
//	printf("final: p=%d, q=%x\n", p, q); fflush(stdout);
	while (p) {
//		printf("p=%d, prev=%d, id=%d\n", p, dp[p] >> 7, (dp[p] & 127)-2);
		f[(dp[p] & 127)-2] = 1;
		p = dp[p] >> 7;
	}
	for (i = 0; q; i++) {
		if (q & 1) f[fa-1+i] = 1;
		q >>= 1;
	}
	for (i = 0; i < N; i++) pc(f[i]? 'o': 'x');
	pc('\n');
#if 0
	ll s = 0;
	for (i = 0; i < N; i++) if (f[i]) {
		if (i+2 <= fa) s += a[i+2];
		else s += b[i+1-fa];
	}
	printf("sum = %lld\n", s);
#endif
	exit(0);
}

int main()
{
	int i, j, x, ma;
	ll s;
	
	N = (int)in(), X = in(), s = 0, fa = 1;
	for (i = 0; i < N; i++) {
		x = (int)in(), s += x;
		if (x <= LIM) a[++fa] = x;
		else b[fb++] = x;
	}
	if (s == X) { outc(N, 'o'); return 0; }

//	printf("fa=%d, fb=%d\n", fa, fb);
	dp[0] = 1, ma = 0;
	for (i = 2; i <= fa; i++) {
		for (j = ma; j >= 0; j--) {
			if (dp[j] && !dp[j+a[i]]) dp[j+a[i]] = (j << 7) | i;
		}
		ma += a[i];
	}
//	printf("ma=%d\n", ma);
	if (X <= ma && dp[X]) final(X, 0);
	
	i = 1 << fb; while (--i) {
		s = 0, x = i;
		for (j = 0; x; j++) {
			if (x & 1) s += b[j];
			x >>= 1;
		}
		if (s <= X && X-s <= ma && dp[X-s]) final(X-s, i);
	}
	outs("No");
	return 0;
}
0