結果

問題 No.434 占い
ユーザー ei1333333ei1333333
提出日時 2016-10-14 23:04:14
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,231 bytes
コンパイル時間 1,533 ms
コンパイル使用メモリ 160,224 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-02 00:51:06
合計ジャッジ時間 3,600 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
5,248 KB
testcase_01 AC 24 ms
5,376 KB
testcase_02 AC 24 ms
5,376 KB
testcase_03 AC 24 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 23 ms
5,376 KB
testcase_06 AC 26 ms
5,376 KB
testcase_07 AC 23 ms
5,376 KB
testcase_08 AC 24 ms
5,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 27 ms
5,376 KB
testcase_12 AC 40 ms
5,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 26 ms
5,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 40 ms
5,376 KB
testcase_20 AC 161 ms
5,376 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 24 ms
5,376 KB
testcase_24 WA -
testcase_25 AC 3 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 = 1e9 + 7;

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