結果

問題 No.434 占い
ユーザー ei1333333ei1333333
提出日時 2016-10-14 23:53:42
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,171 bytes
コンパイル時間 1,447 ms
コンパイル使用メモリ 161,612 KB
実行使用メモリ 13,756 KB
最終ジャッジ日時 2024-05-01 23:25:54
合計ジャッジ時間 5,954 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
typedef long long int64;

const int mod = 9;

int64 modCombination(int n, int r)
{
  if(n < 0 || r < 0 || r > n) return 0;
  if(n - r < r) r = n - r;
  if(r == 0) return 1;
  if(r == 1) return n;
  int numer[r];
  int denom[r];
  for(int k = 0; k < r; k++) {
    numer[k] = n - r + k + 1;
    denom[k] = k + 1;
  }
  for(int p = 2; p <= r; p++) {
    int piv = denom[p - 1];
    if(piv > 1) {
      int ofst = (n - r) % p;
      for(int k = p - 1; k < r; k += p) {
        numer[k - ofst] /= piv;
        denom[k] /= piv;
      }
    }
  }
  long ret = 1;
  for(int k = 0; k < r; k++) if(numer[k] > 1) ret = ret * numer[k] % mod;
  return ret;
}


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