結果
| 問題 | No.686 Uncertain LIS |
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-02-23 11:33:55 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,868 bytes |
| 記録 | |
| コンパイル時間 | 1,820 ms |
| コンパイル使用メモリ | 163,832 KB |
| 実行使用メモリ | 13,760 KB |
| 最終ジャッジ日時 | 2025-02-23 11:34:02 |
| 合計ジャッジ時間 | 6,312 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 5 RE * 4 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 optimizedSimulatedAnnealing(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) {
// ????????????????
vector<int> newA = A;
int numChanges = rand() % (n / 10); // ???????
// ????????
for (int i = 0; i < numChanges; i++) {
int idx = rand() % n;
newA[idx] = rand() % (range[idx].second - range[idx].first + 1) / 2 + range[idx].first;
}
// ????LIS??
int newLIS = LIS(newA);
// ???????????
if (newLIS > bestLIS) {
bestLIS = newLIS;
bestA = newA;
} else {
// ?????????????????????
double prob = exp((newLIS - bestLIS) / temperature);
if (rand() / double(RAND_MAX) < prob) {
bestLIS = newLIS;
bestA = newA;
}
}
// ??
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 = optimizedSimulatedAnnealing(n, range);
cout << maxLIS << endl;
return 0;
}
vjudge1