結果

問題 No.435 占い(Extra)
ユーザー rickythetarickytheta
提出日時 2016-10-15 00:43:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 174 ms / 2,000 ms
コード長 1,144 bytes
コンパイル時間 1,422 ms
コンパイル使用メモリ 158,700 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 02:39:30
合計ジャッジ時間 4,028 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 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 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 13 ms
5,376 KB
testcase_13 AC 12 ms
5,376 KB
testcase_14 AC 12 ms
5,376 KB
testcase_15 AC 13 ms
5,376 KB
testcase_16 AC 17 ms
5,376 KB
testcase_17 AC 62 ms
5,376 KB
testcase_18 AC 12 ms
5,376 KB
testcase_19 AC 12 ms
5,376 KB
testcase_20 AC 107 ms
5,376 KB
testcase_21 AC 109 ms
5,376 KB
testcase_22 AC 107 ms
5,376 KB
testcase_23 AC 108 ms
5,376 KB
testcase_24 AC 114 ms
5,376 KB
testcase_25 AC 174 ms
5,376 KB
testcase_26 AC 116 ms
5,376 KB
testcase_27 AC 107 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 108 ms
5,376 KB
testcase_30 AC 108 ms
5,376 KB
testcase_31 AC 89 ms
5,376 KB
testcase_32 AC 95 ms
5,376 KB
testcase_33 AC 111 ms
5,376 KB
testcase_34 AC 129 ms
5,376 KB
testcase_35 AC 108 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void solve()’:
main.cpp:11:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |   scanf("%d%d%d%d%d",&n,&x,&a,&b,&m);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:71:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   71 |   scanf("%d",&t);
      |   ~~~~~^~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)

const int inv[] = {0,1,5,0,7,2,0,4,8};
void solve(){
  int n,x,a,b,m;
  scanf("%d%d%d%d%d",&n,&x,&a,&b,&m);
  if(n==1){
    printf("%d\n",x%10);
    return;
  }
  int ab = 1;
  int tri = 0;
  int ans = 0;
  int ac = (n-1)%3;
  int bc = 2;
  bool flag = false;
  REP(i,n-1){
    const int cur = x%10;
    flag |= cur!=0;
    if(tri==0){
      ans += ab*cur%9;
    }else if(tri==1){
      ans += ab*3*cur%9;
    }
    x = ((x^a)+b)%m;
    int aa = n-1-i;
    if(ac==0){
      aa/=3;
      tri++;
      while(aa%3==0){
        aa/=3;
        tri++;
      }
      ac=2;
    }else{
      ac--;
    }
    int bb = i+1;
    if(bc==0){
      bb/=3;
      tri--;
      while(bb%3==0){
        bb/=3;
        tri--;
      }
      bc=2;
    }else{
      bc--;
    }
    ab = ab*aa*inv[bb%9]%9;
  }
  const int cur = x%10;
  flag |= cur!=0;
  ans += cur;
  if(!flag){
    puts("0");
    return;
  }
  ans%=9;
  if(ans==0)ans=9;
  printf("%d\n",ans);
}

int main(){
  int t;
  scanf("%d",&t);
  while(t--)solve();
  return 0;
}
0