結果

問題 No.432 占い(Easy)
コンテスト
ユーザー bal4u
提出日時 2019-05-08 19:53:03
言語 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
結果
WA  
実行時間 -
コード長 1,005 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 240 ms
コンパイル使用メモリ 40,808 KB
最終ジャッジ日時 2026-02-22 03:19:16
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 13 WA * 9
権限があれば一括ダウンロードができます

ソースコード

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, c;
	do c = gc(), *s++ = c & 0xf;
	while (c > ' ');
	*--s = 0;
	return s-p;
}

#define MOD 9

char S[1004];
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(S)-1, s = 0;
		for (i = 0; i <= w; i++) {
			if (S[i] < '9') s += (S[i] & 0xf) * combi(w, i);
		}
		s %= 9;
		if (s == 0) pc('9'); else pc('0'+s);
		pc('\n');
	}
	return 0;
}
0