結果
問題 | No.434 占い |
ユーザー |
![]() |
提出日時 | 2018-05-20 20:40:28 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 18 ms / 2,000 ms |
コード長 | 774 bytes |
コンパイル時間 | 219 ms |
コンパイル使用メモリ | 33,280 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-28 14:46:37 |
合計ジャッジ時間 | 1,308 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 27 |
ソースコード
#include <cstdio>const int inv[] = { 0, 1, 5, 0, 7, 2, 0, 4, 8 };int q, n, x; char s[100009]; short fact[100009];int main() {fact[0] = 1;for (int i = 1; i <= 100000; ++i) {x = i;while (x % 3 == 0) x /= 3;fact[i] = fact[i - 1] * x % 9;}scanf("%d", &q);while (q--) {scanf("%s", s); n = 0;while (s[n]) n++;int ord = 0, mul = 1, ret = 0, f = 0;for (int i = 0; i < n; i++) {if ((s[i] - '0') % 10 != 0) f = 1;ret = (ret + (s[i] - '0') % 10 * (ord == 0 ? mul : (ord == 1 ? mul % 3 * 3 : 0))) % 9;x = i + 1;while (x % 3 == 0) x /= 3, ord--;mul = mul * inv[x % 9] % 9;x = n - i - 1;while (x != 0 && x % 3 == 0) x /= 3, ord++;mul = mul * x % 9;}printf("%d\n", ret + (ret == 0 && f == 1 ? 9 : 0));}return 0;}