結果
| 問題 |
No.2796 Small Matryoshka
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-06-28 22:26:36 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,109 bytes |
| コンパイル時間 | 737 ms |
| コンパイル使用メモリ | 76,340 KB |
| 実行使用メモリ | 10,624 KB |
| 最終ジャッジ日時 | 2024-06-28 22:26:41 |
| 合計ジャッジ時間 | 5,034 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 2 WA * 1 TLE * 1 -- * 15 |
ソースコード
#include <vector>
#include <algorithm>
#include <iostream>
#include <limits.h>
using namespace std;
struct Doll {
int r, R;
};
// Comparator to sort dolls by outer diameter
bool compareDolls(const Doll& a, const Doll& b) {
return a.R < b.R;
}
int minScalingOperations(vector<Doll>& dolls) {
int n = dolls.size();
// Sort dolls based on their outer diameters
sort(dolls.begin(), dolls.end(), compareDolls);
vector<int> dp(n, INT_MAX);
dp[0] = 0; // No scaling needed for the first doll
for (int i = 1; i < n; ++i) {
for (int j = 0; j < i; ++j) {
if (dolls[j].R <= dolls[i].r) {
dp[i] = min(dp[i], dp[j]);
}
}
// Consider scaling operation if no valid nesting found
if (dp[i] == INT_MAX) {
dp[i] = dp[i-1] + 1;
}
}
return dp[n-1];
}
int main() {
int N;
cin >> N;
vector<Doll> dolls(N);
for (int i = 0; i < N; ++i) {
cin >> dolls[i].r >> dolls[i].R;
}
int result = minScalingOperations(dolls);
cout << result << endl;
return 0;
}