結果

問題 No.129 お年玉(2)
ユーザー IL_msta
提出日時 2015-07-03 06:36:36
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
RE  
実行時間 -
コード長 1,144 bytes
コンパイル時間 643 ms
コンパイル使用メモリ 84,952 KB
実行使用メモリ 393,920 KB
最終ジャッジ日時 2024-07-07 22:43:47
合計ジャッジ時間 65,889 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 3
other RE * 46
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:64:38: warning: iteration 5000 invokes undefined behavior [-Waggressive-loop-optimizations]
   64 |         rep(i,maxC)rep(j,maxC)c[i][j]=-1;
      |                               ~~~~~~~^~~
main.cpp:17:39: note: within this loop
   17 | #define REP(i, x, n) for(int i = x; i < n; i++)
      |                                       ^
main.cpp:18:18: note: in expansion of macro ‘REP’
   18 | #define rep(i,n) REP(i,0,n)
      |                  ^~~
main.cpp:64:20: note: in expansion of macro ‘rep’
   64 |         rep(i,maxC)rep(j,maxC)c[i][j]=-1;
      |                    ^~~

ソースコード

diff #

#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>

#include <algorithm>
#include <cmath>

#include <string>
#include <list>
#include <queue>
#include <vector>
#include <complex>
#include <set>

/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
/////////
typedef long long LL;
typedef long double LD;
/////////
using namespace::std;
/////////
const LL mod = (LL)1e9;
const int maxC = 10000;
LL c[maxC][maxC/2];

LL ccc(LL n,LL k){
	LL ans;
	LL kk = min(k,n-k);
	if(n<maxC && kk < maxC && c[n][kk] != -1){
		ans = c[n][kk];
	}
	else if(kk ==0 ){
		if(n<maxC){
			c[n][kk] = 1;
		}
		ans = 1;
	}else if( kk==1){
		if(n<maxC){
			c[n][kk] = n%mod;
		}
		ans = n%mod;
	}
	else{
		ans = (ccc(n-1,kk-1)%mod+ccc(n-1,kk)%mod)%mod;
		if(n<maxC && kk < maxC){
			c[n][kk] = ans;
		}
	}
	return ans;
}
int main(void){
    std::cin.tie(0); 
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed;//
    //cout << setprecision(6);//
    
	LL N,M;
	cin>>N>>M;
	LL ama = (N%(M*1000))/1000;
	rep(i,maxC)rep(j,maxC)c[i][j]=-1;
	//N C ama
	P(ccc(M,ama));
    return 0;
}
0