結果
| 問題 |
No.686 Uncertain LIS
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-02-23 11:36:42 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,527 bytes |
| コンパイル時間 | 2,029 ms |
| コンパイル使用メモリ | 162,760 KB |
| 実行使用メモリ | 11,560 KB |
| 最終ジャッジ日時 | 2025-02-23 11:36:49 |
| 合計ジャッジ時間 | 5,905 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 5 WA * 4 TLE * 1 -- * 26 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
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;
}
int bestLIS = LIS(A);
vector<int> bestA = A;
double temperature = 100.0;
double coolingRate = 0.995;
while (temperature > 1e-7) {
int idx = rand() % n;
int oldVal = A[idx];
A[idx] = rand() % (range[idx].second - range[idx].first + 1) + range[idx].first;
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 res = 0;
for (int i = 1; i <= 10;i++ )
res = max(res, simulatedAnnealing(n, range));
cout<<res;
return 0;
}
vjudge1