結果
問題 |
No.686 Uncertain LIS
|
ユーザー |
![]() |
提出日時 | 2025-02-23 11:22:38 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,762 bytes |
コンパイル時間 | 1,737 ms |
コンパイル使用メモリ | 162,636 KB |
実行使用メモリ | 13,632 KB |
最終ジャッジ日時 | 2025-02-23 11:22:44 |
合計ジャッジ時間 | 6,590 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 4 WA * 5 TLE * 1 -- * 26 |
ソースコード
#include <bits/stdc++.h> using namespace std; // ??LIS????? int LIS(vector<int>& A) { vector<int> dp; for (int x : A) { auto it = lower_bound(dp.begin(), dp.end(), x); if (it == dp.end()) dp.push_back(x); else *it = x; } return dp.size(); } // ?????? int simulatedAnnealing(int n, vector<pair<int, int>>& range) { // ??????????????? vector<int> A(n); for (int i = 0; i < n; i++) { A[i] = rand() % (range[i].second - range[i].first + 1) + range[i].first; } // ????LIS?? int bestLIS = LIS(A); vector<int> bestA = A; // ??????? double temperature = 100.0; double coolingRate = 0.995; // ?????? while (temperature > 1e-6) { // ???????????????? int idx = rand() % n; int oldVal = A[idx]; A[idx] = rand() % (range[idx].second - range[idx].first + 1) + range[idx].first; // ????LIS?? int newLIS = LIS(A); // ??????????? if (newLIS > bestLIS) { bestLIS = newLIS; bestA = A; } else { // ????????????????????? double prob = exp((newLIS - bestLIS) / temperature); if (rand() / double(RAND_MAX) < prob) { bestLIS = newLIS; bestA = A; } else { // ????? A[idx] = oldVal; } } // ?? temperature *= coolingRate; } return bestLIS; } int main() { int n; cin >> n; // ???? vector<pair<int, int>> range(n); for (int i = 0; i < n; i++) { cin >> range[i].first >> range[i].second; } // ?????????? int maxLIS = simulatedAnnealing(n, range); cout << maxLIS << endl; return 0; }