結果

問題 No.434 占い
ユーザー KoryKory
提出日時 2016-10-15 01:43:35
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,108 bytes
コンパイル時間 1,408 ms
コンパイル使用メモリ 161,392 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-02 01:15:48
合計ジャッジ時間 2,839 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

// macros
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define INT_IN(a) int a; cin >> a
#define STR_IN(s) string s; cin >> s
#define PRINTLN(s) cout << s << endl
#define PRINTDOUBLELN(s) cout << setprecision(12) << (s) << endl;

// util functions
template<class T> inline T sqr(T x) {return x*x;}

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template <typename T>inline T max(vector<T> v){T max=v[0]; FOR(i, 1, v.size())max=MAX(v[i], max); return max;}
template <typename T>inline T min(vector<T> v){T min=v[0]; FOR(i, 1, v.size())min=MIN(v[i], min); return min;}
template <typename T>inline vector<T> concat(vector<T> a, vector<T> b){vector<T> ab; ab.reserve(a.size()+b.size());ab.insert(ab.end(),a.begin(),a.end());ab.insert(ab.end(),b.begin(),b.end());return ab;}

// types
typedef long long LL;

// consts
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//debug
#define dump(x)  #x << " = " << (x) << endl
#define debug(x) #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

int nextCombination(int n, int r, int prevComb){
    return prevComb * (n - r + 1) / r;
}

int main(){
    INT_IN(T);
    REP(i, T){
        STR_IN(S);
        int l = S.length();
        if(l == 1){
            PRINTLN(S);
        }else{
            vector<int> iS;
            REP(j, l) iS.push_back(S[j] - '0');
            bool isZero = true;
            REP(j, l) isZero &= iS[l];
            if(isZero){
                PRINTLN(0);
                continue;
            }
            int n = l - 1;
            int sum = 0;
            int combination = 1;
            REP(r, l){
                sum += combination % 9 * iS[r];
                combination = nextCombination(n, r + 1, combination);
            }
            if(sum % 9 != 0)sum %= 9;
            else sum = 9;
            PRINTLN(sum);
        }
    }
    return 0;
}

0