結果
問題 | No.873 バイナリ、ヤバいなり!w |
ユーザー | bal4u |
提出日時 | 2019-08-31 12:18:30 |
言語 | C (gcc 12.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,523 bytes |
コンパイル時間 | 898 ms |
コンパイル使用メモリ | 29,712 KB |
実行使用メモリ | 4,388 KB |
最終ジャッジ日時 | 2023-09-06 11:57:42 |
合計ジャッジ時間 | 2,855 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 62 ms
4,380 KB |
testcase_01 | WA | - |
testcase_02 | AC | 140 ms
4,376 KB |
testcase_03 | AC | 115 ms
4,380 KB |
testcase_04 | WA | - |
testcase_05 | AC | 1 ms
4,376 KB |
testcase_06 | AC | 1 ms
4,376 KB |
testcase_07 | RE | - |
testcase_08 | AC | 26 ms
4,376 KB |
testcase_09 | AC | 1 ms
4,380 KB |
testcase_10 | AC | 0 ms
4,384 KB |
testcase_11 | AC | 0 ms
4,376 KB |
testcase_12 | AC | 7 ms
4,380 KB |
testcase_13 | AC | 1 ms
4,380 KB |
testcase_14 | AC | 1 ms
4,380 KB |
testcase_15 | AC | 0 ms
4,380 KB |
testcase_16 | AC | 1 ms
4,376 KB |
testcase_17 | AC | 0 ms
4,376 KB |
testcase_18 | AC | 0 ms
4,380 KB |
testcase_19 | AC | 1 ms
4,376 KB |
testcase_20 | AC | 0 ms
4,376 KB |
testcase_21 | AC | 0 ms
4,380 KB |
testcase_22 | AC | 0 ms
4,380 KB |
testcase_23 | AC | 1 ms
4,380 KB |
testcase_24 | AC | 1 ms
4,380 KB |
testcase_25 | AC | 1 ms
4,380 KB |
testcase_26 | AC | 0 ms
4,388 KB |
testcase_27 | AC | 0 ms
4,376 KB |
testcase_28 | AC | 1 ms
4,380 KB |
testcase_29 | AC | 0 ms
4,380 KB |
testcase_30 | AC | 1 ms
4,380 KB |
testcase_31 | AC | 1 ms
4,380 KB |
testcase_32 | AC | 3 ms
4,380 KB |
testcase_33 | AC | 1 ms
4,376 KB |
testcase_34 | AC | 16 ms
4,380 KB |
testcase_35 | AC | 159 ms
4,380 KB |
testcase_36 | AC | 76 ms
4,380 KB |
testcase_37 | AC | 160 ms
4,380 KB |
testcase_38 | AC | 159 ms
4,380 KB |
コンパイルメッセージ
main.c: 関数 ‘in’ 内: main.c:8:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration] 8 | #define gc() getchar_unlocked() | ^~~~~~~~~~~~~~~~ main.c:16:24: 備考: in expansion of macro ‘gc’ 16 | int n = 0, c = gc(); | ^~ main.c: 関数 ‘outs’ 内: main.c:9:15: 警告: 関数 ‘putchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration] 9 | #define pc(c) putchar_unlocked(c) | ^~~~~~~~~~~~~~~~ main.c:21:33: 備考: in expansion of macro ‘pc’ 21 | void outs(char *s) { while (*s) pc(*s++); } | ^~ main.c: 関数 ‘main’ 内: main.c:63:57: 警告: iteration 277 invokes undefined behavior [-Waggressive-loop-optimizations] 63 | i = 0; while (i < LIM) s01[i++] = '0', s01[i++] = '1'; | ~~~~~~~~~^~~~~ main.c:63:25: 備考: within this loop 63 | i = 0; while (i < LIM) s01[i++] = '0', s01[i++] = '1'; | ^
ソースコード
// yukicoder: 873 バイナリ、ヤバいなり!w // 2019.8.31 bal4u #include <stdio.h> #include <stdlib.h> #if 1 #define gc() getchar_unlocked() #define pc(c) putchar_unlocked(c) #else #define gc() getchar() #define pc(c) putchar(c) #endif int in() { // 非負整数の入力 int n = 0, c = gc(); do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0'); return n; } void outs(char *s) { while (*s) pc(*s++); } #define INF 0x01010101 #define LIM 555 int N; int a[LIM]; int w; int dp[300005]; char s01[LIM]; int last = '1'; void pr(int w) { static char *s = s01; last = s[w], s[w] = 0; outs(s); s[w] = last; s = (last == '0')? s01+1: s01; } int pr_odd(int k) { int i; for (i = 1; a[i] <= k; i+=2) { if (dp[k] == dp[k-a[i]] + i) { k -= a[i], pr(i); return k; } } return -1; } int pr_even(int k) { int i = w; if (i & 1) i--; while (k < a[i]) i -= 2; for ( ; i > 0; i-=2) { if (dp[k] == dp[k-a[i]] + i) { k -= a[i], pr(i); return k; } } return -1; } int main() { int i, j, k; N = in(); if (N == 1) { puts("0"); return 0; } w = 0; while (w*w <= N) w++, a[w] = w*w; i = 0; while (i < LIM) s01[i++] = '0', s01[i++] = '1'; for (j = 1; j <= N; j++) { int x = INF; for (i = 1; a[i] <= j; i++) if (dp[j-a[i]] + i < x) x = dp[j-a[i]] + i, k = i; dp[j] = dp[j-a[k]] + k; } k = N; while (k > 0) { if (last == '1') { if ((j = pr_odd(k)) >= 0) k = j; else k = pr_even(k); } else { if ((j = pr_even(k)) >= 0) k = j; else k = pr_odd(k); } } pc('\n'); return 0; }