結果

問題 No.434 占い
ユーザー tossytossy
提出日時 2016-10-23 00:00:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,705 bytes
コンパイル時間 1,236 ms
コンパイル使用メモリ 95,048 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-05-02 22:38:47
合計ジャッジ時間 6,462 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,752 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 712 ms
5,376 KB
testcase_09 AC 82 ms
5,376 KB
testcase_10 AC 11 ms
5,376 KB
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 704 ms
5,376 KB
testcase_14 AC 77 ms
5,376 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 <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define fi first
#define se second

#define INF 2147483600

vector<int> primes;

// combinarion nCr mod M
long comb(long n, long r, long mod){
  if(r>n-r) r=n-r;
  vector<int> a(n);
  rep(i,r) a[i]=n-i;

  for(int p : primes){
    if(p>r) break;
    for(long q=p; q<=r; q*=p){
      for(int i=n%q, j=0; j<r/q; i+=q,j++){
        // r! のうち,qで割れる値はr/q個ある.また,a[i]はpでわりきれる
        a[i] /= p;
      }
    }
  }

  long mul=1;
  rep(i,r) mul = mul*a[i]%mod;
  return mul;
}

int main(){
  // sieve of Erastosthenes
  #define SZ 100000
  vector<bool> arr(SZ+2, true);
  arr[0]=arr[1]=false;
  for(int i=4;i<=SZ;i+=2) arr[i]=false;
  primes.pb(2);
  for(int i=3; i<=SZ/2; i+=2){
    if(arr[i]){
      primes.pb(i);
      for(int j=i*2; j<=SZ; j+=i) arr[j]=false;
    }
  }

  int tc;
  scanf("%d\n", &tc);
  rep(loops, tc){
    vector<int> vec;
    char c;
    while(scanf("%c", &c)){
      if(c=='\n') break;
      vec.pb(c-'0');
    }
    int n =vec.size();

    int res = 0;
    bool isZero = (vec[0]==0);
    rep(i,n){
      if(vec[i]!=0) isZero=false;
      res += vec[i] * comb(n-1, i, 9);
      res %= 9;
    }

    if(!isZero && res==0) res=9;
    printf("%d\n", res);
  }

  return 0;
}
0