結果
| 問題 |
No.711 競技レーティング単調増加
|
| コンテスト | |
| ユーザー |
しらっ亭
|
| 提出日時 | 2017-05-23 00:49:25 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 923 bytes |
| コンパイル時間 | 1,925 ms |
| コンパイル使用メモリ | 178,220 KB |
| 実行使用メモリ | 10,624 KB |
| 最終ジャッジ日時 | 2024-09-19 10:32:42 |
| 合計ジャッジ時間 | 5,853 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 15 TLE * 1 -- * 25 |
ソースコード
// O(n^2) のTLE解を unordered_map にして、定数倍高速化したやつ
#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];
unordered_map<int, int> q1, q2;
auto &cur = q1;
auto &nex = q2;
cur[0] = 0;
for (int i = 0; i < n; i++) {
for (auto cl : cur) {
int c = cl.first;
int l = cl.second;
if (l < A[i]) {
if (nex.count(c) == 0 || nex[c] > A[i]) {
nex[c] = A[i];
}
}
if (nex.count(c + 1) == 0 || nex[c + 1] > l + 1) {
nex[c + 1] = l + 1;
}
}
swap(cur, nex);
nex.clear();
}
int ans = 1e9;
for (auto cl : cur) {
ans = min(ans, cl.first);
}
return ans;
//return cur.begin()->fst; // mapならこちら
}
int main() {
cin.tie(nullptr); ios::sync_with_stdio(false);
cout << solve() << endl;
return 0;
}
しらっ亭