結果
| 問題 |
No.432 占い(Easy)
|
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-05-08 20:16:22 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 1,126 bytes |
| コンパイル時間 | 146 ms |
| コンパイル使用メモリ | 30,848 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-02 00:31:07 |
| 合計ジャッジ時間 | 1,007 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 22 |
コンパイルメッセージ
main.c: In function 'in':
main.c:8:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
8 | #define gc() getchar_unlocked()
| ^~~~~~~~~~~~~~~~
main.c:16:24: note: in expansion of macro 'gc'
16 | int n = 0, c = gc();
| ^~
main.c: In function 'main':
main.c:9:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration]
9 | #define pc(c) putchar_unlocked(c)
| ^~~~~~~~~~~~~~~~
main.c:64:17: note: in expansion of macro 'pc'
64 | pc('0'+s), pc('\n');
| ^~
ソースコード
// yukicoder: No.432 占い(Easy)
// 2019.4.17 bal4u
#include <stdio.h>
#include <string.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), c = gc(); while (c >= '0');
return n;
}
int ins(char *s) // 文字列の入力 スペース以下の文字で入力終了
{
char *p = s;
do *s = gc();
while (*s++ > ' ');
*--s = 0;
return s - p;
}
#define MOD 9
char S[1004], *p;
char tbl[1001][1001];
int combi(int n, int k)
{
int ans;
if (tbl[n][k] >= 0) return tbl[n][k];
if ((k << 1) > n) k = n-k;
if (k == 0) ans = 1;
else if (k == 1) ans = n % MOD;
else ans = (combi(n-1, k) + combi(n-1, k-1)) % MOD;
return tbl[n][k] = ans;
}
int main()
{
int i, w, s, T;
memset(tbl, -1, sizeof(tbl));
T = in();
while (T--) {
w = ins(p = S)-1;
while (*p == '0') p++;
if (*p == 0) s = 0;
else {
s = 0; for (i = 0; i <= w; i++) {
if (S[i] < '9') s += (S[i] & 0xf) * combi(w, i);
}
s %= 9;
if (s == 0) s = 9;
}
pc('0'+s), pc('\n');
}
return 0;
}
bal4u