結果
問題 | No.535 自然数の収納方法 |
ユーザー | Pachicobue |
提出日時 | 2017-06-29 14:08:27 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 54 ms / 2,000 ms |
コード長 | 4,339 bytes |
コンパイル時間 | 1,415 ms |
コンパイル使用メモリ | 168,780 KB |
実行使用メモリ | 66,004 KB |
最終ジャッジ日時 | 2024-10-04 16:36:37 |
合計ジャッジ時間 | 2,665 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
7,876 KB |
testcase_03 | AC | 1 ms
6,816 KB |
testcase_04 | AC | 3 ms
6,824 KB |
testcase_05 | AC | 2 ms
6,820 KB |
testcase_06 | AC | 3 ms
7,852 KB |
testcase_07 | AC | 12 ms
26,116 KB |
testcase_08 | AC | 32 ms
51,212 KB |
testcase_09 | AC | 44 ms
56,832 KB |
testcase_10 | AC | 52 ms
61,824 KB |
testcase_11 | AC | 12 ms
14,464 KB |
testcase_12 | AC | 22 ms
34,432 KB |
testcase_13 | AC | 2 ms
5,248 KB |
testcase_14 | AC | 25 ms
27,648 KB |
testcase_15 | AC | 51 ms
63,488 KB |
testcase_16 | AC | 34 ms
50,432 KB |
testcase_17 | AC | 52 ms
65,024 KB |
testcase_18 | AC | 2 ms
5,248 KB |
testcase_19 | AC | 53 ms
65,792 KB |
testcase_20 | AC | 53 ms
65,792 KB |
testcase_21 | AC | 54 ms
65,920 KB |
testcase_22 | AC | 54 ms
66,004 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define RFOR(i, a, b) for (ll i = (b)-1; i >= (a); i--) #define rep(i, n) for (ll i = 0; i < (n); i++) #define rep1(i, n) for (ll i = 1; i <= (n); i++) #define rrep(i, n) for (ll i = (n)-1; i >= 0; i--) #define pb push_back #define mp make_pair #define fst first #define snd second #define show(x) cout << #x << " = " << x << endl #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define pii pair<int, int> namespace is_stl_container_impl { template <typename T> struct is_stl_container : false_type { }; template <typename T, size_t N> struct is_stl_container<array<T, N>> : true_type { }; template <typename... Args> struct is_stl_container<vector<Args...>> : true_type { }; template <typename... Args> struct is_stl_container<deque<Args...>> : true_type { }; template <typename... Args> struct is_stl_container<list<Args...>> : true_type { }; template <typename... Args> struct is_stl_container<forward_list<Args...>> : true_type { }; template <typename... Args> struct is_stl_container<set<Args...>> : true_type { }; template <typename... Args> struct is_stl_container<multiset<Args...>> : true_type { }; template <typename... Args> struct is_stl_container<map<Args...>> : true_type { }; template <typename... Args> struct is_stl_container<multimap<Args...>> : true_type { }; template <typename... Args> struct is_stl_container<unordered_set<Args...>> : true_type { }; template <typename... Args> struct is_stl_container<unordered_multiset<Args...>> : true_type { }; template <typename... Args> struct is_stl_container<unordered_map<Args...>> : true_type { }; template <typename... Args> struct is_stl_container<unordered_multimap<Args...>> : true_type { }; template <typename... Args> struct is_stl_container<stack<Args...>> : true_type { }; template <typename... Args> struct is_stl_container<queue<Args...>> : true_type { }; template <typename... Args> struct is_stl_container<priority_queue<Args...>> : true_type { }; } // namespace is_stl_container_impl //type trait to utilize the implementation type traits as well as decay the type template <typename T> struct is_stl_container { static constexpr bool const value = is_stl_container_impl::is_stl_container<decay_t<T>>::value; }; template <typename T> typename enable_if<is_stl_container<T>::value, ostream&>::type operator<<(ostream& os, const T& container) { os << "["; for (const auto& p : container) { os << p << ","; } os << "]"; return os; } template <typename S, typename T> ostream& operator<<(ostream& os, const pair<S, T>& p) { os << "(" << p.first << "," << p.second << ")"; return os; } using ll = long long; constexpr ll MOD = 1000000007; template <typename T> constexpr T INF = numeric_limits<T>::inf() / 100; constexpr int MAX = 2000; ll dp[MAX][MAX + 1]; // dp[i:a_iまで決定][a_iの値] ll sum[MAX][MAX + 1]; // sum[i][j] = dp[i][0]+dp[i][1]+...+dp[i][j] // a0<=a1 // a1<=a2 // a2<=a3+1 // ... // a(N-1)<=aN+(N-2) inline int d(const int n) { if (n == 1) { return 0; } else { return n - 2; } } int main() { int N; cin >> N; for (int i = 1; i <= N; i++) { dp[0][i] = 1; sum[0][i] = (sum[0][i - 1] + 1) % MOD; } for (int i = 1; i < N; i++) { for (int j = 1; j <= N; j++) { const int inf = min(N, j + d(i)); const ll su = sum[i - 1][inf] - sum[i - 1][0]; dp[i][j] = su; sum[i][j] = (sum[i][j - 1] + su) % MOD; } } ll sumu = 0; for (int i = 1; i <= N; i++) { sumu = (sumu + dp[N - 1][i]) % MOD; } for (int i = 0; i < N; i++) { for (int j = 0; j <= N; j++) { dp[i][j] = 0; sum[i][j] = 0; } } dp[0][1] = 1; for (int i = 1; i <= N; i++) { sum[0][i] = (sum[0][i - 1] + dp[0][i]) % MOD; } for (int i = 1; i < N; i++) { for (int j = 1; j <= N; j++) { const int inf = min(N, j + d(i)); const ll su = sum[i - 1][inf] - sum[i - 1][0]; dp[i][j] = su; sum[i][j] = (sum[i][j - 1] + su) % MOD; } } const ll remov = dp[N - 1][N]; cout << (sumu - remov + MOD) % MOD << endl; return 0; }