結果

問題 No.434 占い
ユーザー tossytossy
提出日時 2016-10-23 01:22:57
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,697 bytes
コンパイル時間 773 ms
コンパイル使用メモリ 85,896 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-15 11:10:40
合計ジャッジ時間 2,218 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 4 ms
4,384 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 4 ms
4,376 KB
testcase_13 AC 5 ms
4,376 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 36 ms
4,376 KB
testcase_16 AC 31 ms
4,376 KB
testcase_17 AC 24 ms
4,380 KB
testcase_18 AC 11 ms
4,380 KB
testcase_19 AC 11 ms
4,380 KB
testcase_20 AC 25 ms
4,376 KB
testcase_21 AC 36 ms
4,380 KB
testcase_22 AC 30 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 31 ms
4,380 KB
testcase_25 AC 39 ms
4,376 KB
testcase_26 AC 17 ms
4,376 KB
testcase_27 AC 21 ms
4,376 KB
testcase_28 AC 22 ms
4,380 KB
testcase_29 AC 13 ms
4,376 KB
testcase_30 AC 20 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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;

// x^n mod
long mod_pow(long x, long n, long mod){
  long res=1;
  while(n>0){
    if(n&1) res=res*x%mod;
    x=x*x%mod;
    n>>=1;
  }
  return res;
}

int main(){
  #define SZ 100000
  vector<int> divs(SZ+1, 0); //divs[i] := iを割り切る素数のひとつ, 素数なら0
  for(int i=2; i<=SZ; i++) if(divs[i]==0){
    for(long j=(long)i*i; j<=SZ; j+=i) divs[j]=i;
  }

  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);

    vector<int> comb(9,0); //combinationの素因数分解

    rep(i,n){
      if(vec[i]!=0) isZero=false;

      long cc=1;
      repl(j,2,9) cc *= mod_pow(j, comb[j], 9);
      res = (res + vec[i] * cc) % 9;

      int a = n-1-i;
      int b = i+1;
      while(divs[a]>0){
        comb[divs[a]%9]++;
        a /= divs[a];
      }
      comb[a%9]++;
      while(divs[b]>0){
        comb[divs[b]%9]--;
        b /= divs[b];
      }
      comb[b%9]--;
    }

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

  return 0;
}
0