結果
| 問題 | 
                            No.434 占い
                             | 
                    
| コンテスト | |
| ユーザー | 
                             ei1333333
                         | 
                    
| 提出日時 | 2016-10-14 23:04:14 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,231 bytes | 
| コンパイル時間 | 1,957 ms | 
| コンパイル使用メモリ | 160,120 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-22 09:41:23 | 
| 合計ジャッジ時間 | 3,747 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 11 WA * 16 | 
ソースコード
#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;
    }
  }
}
            
            
            
        
            
ei1333333