結果

問題 No.554 recurrence formula
ユーザー notetonousnotetonous
提出日時 2017-08-12 00:28:33
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 825 bytes
コンパイル時間 427 ms
コンパイル使用メモリ 55,720 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 00:15:46
合計ジャッジ時間 1,132 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 5 ms
5,376 KB
testcase_16 AC 4 ms
5,376 KB
testcase_17 AC 4 ms
5,376 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 27 ms
5,376 KB
testcase_20 AC 27 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
using namespace std;
#define M 1e9+7
long long int N;
long long int a[100001],b[100001];
long long int ans;
long long int mod=M;
void add(long long int *bit,int i,long long int x){
  while(i<=N){
    bit[i]+=x;
    bit[i]%=mod;
    i+=i&-i;
  }
}
long long int sum(long long int *bit ,int i){
  long long int s=0;
  while(i>0){
    s+=bit[i];
    s%=mod;
    i -=i& -i;
  }
  return  s%mod;
}
int main(){
  for(int i=0;i<100001;i++){a[i]=0;b[i]=0;}
  cin >> N;
  add(a,1,1);
  if(N==1){
    cout << "1" << endl;
      return 0;
  }
  for(int i=2;i<=N;i++){
    if(i%2==0){
      ans=i*sum(a,i/2);
      ans%=mod;
      add(b,i/2,ans%mod);
    }
    else{
      ans=i*sum(b,i/2);
      ans%=mod;
      add(a,i/2+1,ans%mod);
    }
    if(i==N)cout << ans%mod << endl;
  }
 

  return 0;
}
0