結果

問題 No.435 占い(Extra)
ユーザー 🐬hec🐬hec
提出日時 2016-05-03 22:55:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 181 ms / 2,000 ms
コード長 1,547 bytes
コンパイル時間 1,510 ms
コンパイル使用メモリ 165,680 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-07-30 00:02:39
合計ジャッジ時間 5,020 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 3 ms
4,384 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 14 ms
4,376 KB
testcase_13 AC 13 ms
4,380 KB
testcase_14 AC 14 ms
4,376 KB
testcase_15 AC 15 ms
4,376 KB
testcase_16 AC 19 ms
4,376 KB
testcase_17 AC 73 ms
4,376 KB
testcase_18 AC 13 ms
4,376 KB
testcase_19 AC 14 ms
4,380 KB
testcase_20 AC 120 ms
4,376 KB
testcase_21 AC 121 ms
4,376 KB
testcase_22 AC 121 ms
4,376 KB
testcase_23 AC 122 ms
4,380 KB
testcase_24 AC 128 ms
4,376 KB
testcase_25 AC 181 ms
4,380 KB
testcase_26 AC 121 ms
4,380 KB
testcase_27 AC 122 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 122 ms
4,380 KB
testcase_30 AC 121 ms
4,380 KB
testcase_31 AC 99 ms
4,380 KB
testcase_32 AC 106 ms
4,376 KB
testcase_33 AC 123 ms
4,376 KB
testcase_34 AC 146 ms
4,376 KB
testcase_35 AC 121 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

using namespace std;
using ll=long long;

const int t_limit=100000;
const int n_limit=10000000;

const int num_idx[10]={0,0,1,0,2,5,0,4,3,0};
const int two_idx[6]={1,2,4,8,7,5};

int main(void){
    int t=0,sum=0;
    scanf("%d",&t);
    assert(1<=t && t<=t_limit);
    
    rep(loop,t){
        int n,x,a,b,m;
        scanf("%d %d %d %d %d",&n,&x,&a,&b,&m);
        assert(1<=n && n<=n_limit);
        assert(0<=x && x<=1e9);
        assert(0<=a && a<=1e9);
        assert(0<=b && b<=1e9);
        assert(1<=m && m<=1e9);
        sum+=n;

        bool allzero=true;
        int answer=0,num=n-1,den=1,two=0,three=0,tmp=0;

        rep(i,n){
            int s=x%10;
            x=((x^a)+b)%m;
            if(s!=0) allzero=false;

            if(three<=1){
                int cur=s;
                cur=s*two_idx[two%6]*(three?3:1);
                answer+=cur;
            }
            
            if(i==n-1) break;

            tmp=num;
            while(tmp%3==0) tmp/=3,three++;
            two+=(num_idx[tmp%9]);
            
            tmp=den;
            while(tmp%3==0) tmp/=3,three--;
            two+=(6-num_idx[tmp%9]);
        
            num--,den++;
        }

        answer%=9;
        if(allzero==false && answer==0) answer=9;
        printf("%d\n",answer);
    }
    assert(sum<=n_limit);
    return 0;
}
0