結果
問題 |
No.5 数字のブロック
|
ユーザー |
![]() |
提出日時 | 2019-04-22 06:57:35 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1 ms / 5,000 ms |
コード長 | 634 bytes |
コンパイル時間 | 242 ms |
コンパイル使用メモリ | 28,928 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-18 14:21:45 |
合計ジャッジ時間 | 986 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
コンパイルメッセージ
main.c: In function 'in': main.c:9:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration] 9 | #define gc() getchar_unlocked() | ^~~~~~~~~~~~~~~~ main.c:15:24: note: in expansion of macro 'gc' 15 | int n = 0, c = gc(); | ^~
ソースコード
// yukicoder: No.5 数字のブロック // 2019.4.7 bal4u // ソートして貪欲法で解いてみる #include <stdio.h> //// 高速入力 #if 1 #define gc() getchar_unlocked() #else #define gc() getchar() #endif int in() // 非負整数の入力 { int n = 0, c = gc(); do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0'); return n; } int f[10005]; int main() { int i, s, L, N, ans; L = in(), N = in(); for (i = 0; i < N; i++) f[in()]++; f[L] = 2; ans = s = 0, i = 0; while (++i) if (f[i]) { if (s + i*f[i] <= L) s += i*f[i], ans += f[i]; else { ans += (L-s)/i; break; } } printf("%d\n", ans); return 0; }