結果

問題 No.434 占い
ユーザー chocoruskchocorusk
提出日時 2019-12-02 10:56:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 149 ms / 2,000 ms
コード長 1,328 bytes
コンパイル時間 965 ms
コンパイル使用メモリ 108,872 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-15 15:36:23
合計ジャッジ時間 2,769 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
int f[100001];
int inv[9]={0, 1, 5, 0, 7, 2, 0, 4, 8};
int main()
{
    f[0]=1;
	for(int i=1; i<=100000; i++){
		int x=i;
		while(x%3==0){
			x/=3;
		}
		f[i]=f[i-1]*x%9;
	}
	int t;
	cin>>t;
	for(int q=0; q<t; q++){
		string s;
		cin>>s;
		int n=s.size();
		int e0=0;
		int n1=n-1;
		while(n1){
			n1/=3;
			e0+=n1;
		}
		bool z=1;
		int sum=0;
		for(int i=0; i<n; i++){
			int e=e0;
			int i1=i, i2=n-1-i;
			while(i1){
				i1/=3;
				e-=i1;
			}
			while(i2){
				i2/=3;
				e-=i2;
			}
			int x=s[i]-'0';
			if(x!=0){
				z=0;
			}
			if(e==0){
				sum+=x*f[n-1]*inv[f[i]]*inv[f[n-1-i]];
				sum%=9;
			}else if(e==1){
				sum+=x*f[n-1]*inv[f[i]]*inv[f[n-1-i]]*3;
				sum%=9;
			}
		}
		if(z) printf("0\n");
		else if(sum==0) printf("9\n");
		else printf("%d\n", sum);
	}
    return 0;
}
0