結果

問題 No.434 占い
ユーザー ei1333333ei1333333
提出日時 2016-10-14 23:08:52
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,225 bytes
コンパイル時間 1,277 ms
コンパイル使用メモリ 160,712 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-02 00:55:52
合計ジャッジ時間 2,637 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 4 ms
5,376 KB
testcase_02 AC 4 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 5 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 18 ms
5,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 148 ms
5,376 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 4 ms
5,376 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
typedef long long int64;

const int mod = 9;

inline int64 modPow(int64 x, int64 n)
{
  if(n == 0) return (1);
  int64 ret = modPow(x, n / 2);
  (ret *= ret) %= mod;
  if(n & 1) (ret *= x) %= mod;
  return (ret);
}

inline int64 modInv(int64 a)
{
  return (modPow(a, mod - 2));
}

inline int64 modCombination(int p, int q)
{
  static int64 fact[202020], rfact[202020];
  if(fact[0] == 0) {
    fact[0] = rfact[0] = 1;
    for(int i = 1; i < 102020; i++) {
      fact[i] = fact[i - 1] * i % mod;
      rfact[i] = modInv(fact[i]);
    }
  }
  if(q < 0 || p < q) return (0);
  return (fact[p] * rfact[q] % mod * rfact[p - q] % mod);
}

int get(char a, char b)
{
  return ((a + b) / 10 + (a + b) % 10);
}

int main()
{
  int T;
  cin >> T;
  while(T--) {
    string S;
    cin >> S;

    bool f = false;
    for(int j = 0; j < S.size(); j++) {
      if(S[j] != '0') break;
      if(j + 1 == S.size()) {
        cout << 0 << endl;
        f = true;
      }
    }
    if(!f) {
      int ans = 0;
      for(int j = 0; j < S.size(); j++) {
        ans = (int) ((ans + (S[j] - '0') * modCombination(S.size() - 1, j)) % 9);
      }
      cout << (ans == 0 ? 9 : ans) << endl;
    }
  }

}
0