結果
問題 |
No.711 競技レーティング単調増加
|
ユーザー |
![]() |
提出日時 | 2017-05-25 04:11:22 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,133 bytes |
コンパイル時間 | 3,289 ms |
コンパイル使用メモリ | 169,240 KB |
実行使用メモリ | 10,880 KB |
最終ジャッジ日時 | 2024-09-19 18:51:20 |
合計ジャッジ時間 | 5,747 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 15 TLE * 1 -- * 25 |
ソースコード
// O(n^2) のTLE解 #include <bits/stdc++.h> using namespace std; int solve() { int n; cin >> n; vector<int> A(n); for (int i = 0; i < n; i++) cin >> A[i]; const int inf = 1e9 + 1e6; vector<int> dp1(n+1), dp2(n+1); vector<int> &cur = dp1; vector<int> &nex = dp2; // dp[i][j] : A[i-1] までを狭義単調増加にするのに j 手かけたときの、A[i-1]の最小値。できないときは inf // cur = dp[i], nex = dp[i+1] です cur[0] = 0; for (int i = 0; i < n; i++) { fill(nex.begin(), nex.end(), inf); for (int j = 0; j < i + 1; j++) { if (cur[j] >= inf) continue; if (cur[j] < A[i]) { // dp[i][j] に A[i] を継ぎ足す nex[j] = min(nex[j], A[i]); } // dp[i][j] に A[i] を操作したものを継ぎ足す nex[j+1] = min(nex[j+1], cur[j] + 1); } swap(cur, nex); } for (int j = 0; j < n; j++) { if (cur[j] < inf) { // j 手でできていれば、それが答え return j; } } assert(false); } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << solve() << endl; return 0; }