結果
問題 | No.294 SuperFizzBuzz |
ユーザー |
|
提出日時 | 2019-12-27 09:29:57 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,701 bytes |
コンパイル時間 | 981 ms |
コンパイル使用メモリ | 103,980 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-15 19:14:19 |
合計ジャッジ時間 | 1,799 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
#include <limits>#include <iostream>#include <algorithm>#include <iomanip>#include <map>#include <set>#include <queue>#include <stack>#include <numeric>#include <bitset>#include <cmath>static const int MOD = 1000000007;using ll = long long;using u32 = unsigned;using u64 = unsigned long long;using namespace std;template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;template <class T, class U>vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }template<class... Ts, class U>auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }int main() {int n;cin >> n;int M = 30;auto dp = make_v(M+1, 3, 2, 0);dp[0][2][1] = 1;for (int i = 0; i < M; ++i) {for (int j = 0; j < 3; ++j) {for (int k = 0; k < 2; ++k) {for (int l = 0; l < 2; ++l) {dp[i+1][(j+l*2)%3][l] += dp[i][j][k];}}}if(dp[i+1][0][0] + dp[i+1][0][1] >= n){M = i+1;break;}else n -= dp[i+1][0][0] + dp[i+1][0][1];}int val = 0;string ans;for (int i = M; i >= 2; --i) {if(dp[i][val][0] >= n){ans += '3';}else {ans += '5';n -= dp[i][val][0];val = (val+1)%3;}}val %= 3;if(val == 1) ans += '5';else ans += '3';ans += '5';cout << ans << "\n";return 0;}