結果

問題 No.44 DPなすごろく
ユーザー itezpaceitezpace
提出日時 2016-09-27 09:58:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 673 bytes
コンパイル時間 609 ms
コンパイル使用メモリ 60,284 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 05:41:11
合計ジャッジ時間 2,152 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
typedef unsigned long long ll;
ll calc(ll a,ll b){
  ll s=a-b+1,s2=b;
  vector<ll> vc,vd;
  while(1){
    if(a<s) break;
    vc.push_back(a);
    vd.push_back(b);
    a-=1;
    b-=1;
  }
  for(int i=0;i<s2;++i){
    for(int j=0;j<s2;++j){
      if(vc[i]%vd[j]==0){
        vc[i]/=vd[j];
        vd[j]=1;
      }
    }
  }
  ll c=1,d=1;
  for(int i=0;i<s2;++i){
    c*=vc[i];
    d*=vd[i];
  }
  ll e=c/d;
  return e;
}
int main(){
  ll N;cin>>N;
  ll ans=1;
  ll end=0;
  if(N%2==0){
    end=N/2;
  } else {
    end=N/2+1;
  }
  for(ll i=N-1;i>=end;--i){
    ans+=calc(i,N-i);
  }
  cout<<ans<<endl;
  return 0;
}
0