結果
問題 | No.266 最終進化を目指せ |
ユーザー |
![]() |
提出日時 | 2016-11-29 17:54:56 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 2,007 bytes |
コンパイル時間 | 2,032 ms |
コンパイル使用メモリ | 172,572 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-27 13:34:37 |
合計ジャッジ時間 | 2,528 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
#include <bits/stdc++.h> using namespace std; using pii = pair<int,int>; using ll = long long; #define rep(i, j) for(int i=0; i < (int)(j); i++) #define repeat(i, j, k) for(int i = (j); i < (int)(k); i++) #define all(v) v.begin(),v.end() #define debug(x) cerr << #x << " : " << x << endl template<class T> bool set_min(T &a, const T &b) { return a > b ? a = b, true : false; } template<class T> bool set_max(T &a, const T &b) { return a < b ? a = b, true : false; } // vector template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; } template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; } // pair template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; } const int INF = 1 << 28; const ll INFL = 1LL << 60; class Solver { public: bool solve() { int N; cin >> N; vector<int> S(N + 1); cin >> S; vector<vector<int>> dp(N + 1); rep(i, N + 1) dp[i].resize(S[i] + 1, INF); rep(s, S[0] + 1) dp[0][s] = s + 1; repeat(n, 1, N + 1) { rep(s, S[n] + 1) { if(dp[n - 1].size() > s) { set_min(dp[n][s], dp[n - 1][s] + 1); } for(int x = 0; x < s and s - x - 1 >= 0; x++) { if(s - x - 1 < s) { assert(0 <= x and x <= S[n]); assert(0 <= s - x - 1 and s - x - 1 <= S[n]); set_min(dp[n][s], dp[n][x] + dp[n][s - x - 1]); } } } } // debug(dp); for(int a : dp[N]) { cout << a << (a == dp[N].back() ? "\n" : " "); } return 0; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); Solver s; s.solve(); return 0; }