結果
問題 |
No.294 SuperFizzBuzz
|
ユーザー |
![]() |
提出日時 | 2018-11-11 15:21:21 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 1,017 bytes |
コンパイル時間 | 2,169 ms |
コンパイル使用メモリ | 195,112 KB |
最終ジャッジ日時 | 2025-01-06 16:24:27 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
#include<bits/stdc++.h> using namespace std; using Int = long long; template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;} //INSERT ABOVE HERE const Int MAX = 50, INF = 1e9; Int dp[MAX][MAX]; signed main(){ Int n; cin>>n; n--; memset(dp,0,sizeof(dp)); dp[0][0]=1; for(Int i=1;i<MAX;i++){ for(Int j=0;j<=i;j++){ dp[i][j]=dp[i-1][j]; if(j) dp[i][j]+=dp[i-1][j-1]; chmin(dp[i][j],INF); } } Int l=1; while(1){ Int res=0; for(Int i=1;i*3<=l;i++) for(Int j=0;i*3+j<=l;j++) if(i*3+j==l) res+=dp[l-1][i*3-1]; if(res<=n) n-=res,l++; else break; } Int c=1; string ans; for(Int d=0;d+1<l;d++){ Int res=0; for(Int i=0;i<=l-(d+2);i++) if((c+i)%3==0) res+=dp[l-(d+2)][i]; if(res<=n){ n-=res; c++; ans.push_back('5'); }else{ ans.push_back('3'); } } cout<<ans<<5<<endl; return 0; }