結果

問題 No.129 お年玉(2)
ユーザー xxxasdfghjkxxxasdfghjk
提出日時 2018-09-12 00:13:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 75 ms / 5,000 ms
コード長 2,295 bytes
コンパイル時間 1,071 ms
コンパイル使用メモリ 72,644 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-18 18:10:47
合計ジャッジ時間 4,119 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
4,376 KB
testcase_01 AC 75 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 30 ms
4,376 KB
testcase_06 AC 52 ms
4,380 KB
testcase_07 AC 61 ms
4,376 KB
testcase_08 AC 40 ms
4,384 KB
testcase_09 AC 54 ms
4,376 KB
testcase_10 AC 60 ms
4,376 KB
testcase_11 AC 38 ms
4,376 KB
testcase_12 AC 50 ms
4,376 KB
testcase_13 AC 54 ms
4,380 KB
testcase_14 AC 52 ms
4,376 KB
testcase_15 AC 42 ms
4,376 KB
testcase_16 AC 49 ms
4,380 KB
testcase_17 AC 60 ms
4,380 KB
testcase_18 AC 56 ms
4,380 KB
testcase_19 AC 60 ms
4,376 KB
testcase_20 AC 60 ms
4,376 KB
testcase_21 AC 71 ms
4,384 KB
testcase_22 AC 42 ms
4,380 KB
testcase_23 AC 64 ms
4,380 KB
testcase_24 AC 61 ms
4,376 KB
testcase_25 AC 39 ms
4,376 KB
testcase_26 AC 42 ms
4,380 KB
testcase_27 AC 41 ms
4,376 KB
testcase_28 AC 74 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 2 ms
4,384 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 9 ms
4,376 KB
testcase_39 AC 15 ms
4,380 KB
testcase_40 AC 38 ms
4,376 KB
testcase_41 AC 23 ms
4,380 KB
testcase_42 AC 11 ms
4,376 KB
testcase_43 AC 11 ms
4,376 KB
testcase_44 AC 74 ms
4,380 KB
testcase_45 AC 6 ms
4,380 KB
testcase_46 AC 15 ms
4,376 KB
testcase_47 AC 70 ms
4,376 KB
testcase_48 AC 41 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int ncrset()’:
main.cpp:53:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^

ソースコード

diff #

#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#define MAX_N 100001
#define INF 2147483647
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long int ll;
struct edge{
  int from,to,cost;
};
typedef vector<vector<edge> > AdjList;
AdjList graph;
typedef pair<int , int> P;
bool comp(const edge& e1, const edge& e2){
  return e1.cost < e2.cost;
}
int E,V;
edge es[100001];
int kruskal(){
  sort(es,es+E,comp);
  init(V);
  int res = 0;
  for(int i=0;i<E;i++){
    edge e = es[i];
    if(!same(e.to,e.from)){
      unite(e.to,e.from);
      res += e.cost;
    }
  }
  return res;
}


long long int MOD = 1000000007;
long long int ruiseki[200001];
int ncrset(){
  ruiseki[0] = 1;
  for(int i=1;i<200001;i++){
    ruiseki[i] = (ruiseki[i-1] * i) % MOD;
  }
}

long long int powld(long long int x,long long int n){
  long long int ans = 1;
  while(n > 0){
    if((n&1) == 1){
      ans = (ans*x)  % MOD;
    }
    x = (x*x) % MOD;
    n >>= 1;
  }
  return ans % MOD;
}

int ncrgyaku(int n,int r){
  long long int gyakuk,gyakur;
  long long int res = 1,x,y,z;
  y = powld(ruiseki[r],MOD-2);
  z = powld(ruiseki[n-r],MOD-2);
  return (((ruiseki[n]*y) % MOD)*z) % MOD;

}

int main()
{
  ll N,M,P,ncr[2][10111];
  ncr[0][1] = 0;
  ncr[0][0] = 1;
  ncr[1][0] = 1;
  ncr[1][1] = 1;
  
  cin >> N >> M;
  P = (N/1000) % M;
  for(int i=0;i<M;i++){
    ncr[i%2][0] = 1;
    ncr[i%2][i] = 1;
    for(int j=0;j<=i;j++){
        ncr[(i+1)%2][j+1] = (ncr[i%2][j+1] + ncr[i%2][j])%1000000000;
    }
  }
  
  
  cout << ncr[M%2][P] << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}


0