結果

問題 No.432 占い(Easy)
コンテスト
ユーザー bal4u
提出日時 2019-05-08 20:16:22
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,126 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 339 ms
コンパイル使用メモリ 40,644 KB
最終ジャッジ日時 2026-02-22 03:19:18
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

// 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;
}
0