結果
| 問題 |
No.2796 Small Matryoshka
|
| コンテスト | |
| ユーザー |
Moss_Local
|
| 提出日時 | 2024-06-28 21:35:48 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,224 bytes |
| コンパイル時間 | 1,611 ms |
| コンパイル使用メモリ | 111,352 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-28 21:35:55 |
| 合計ジャッジ時間 | 3,471 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 6 WA * 13 |
ソースコード
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
struct Matryoshka {
int r, R;
};
// 外径を基準に昇順でソートするための比較関数
bool compare(const Matryoshka &a, const Matryoshka &b) {
return a.R < b.R || (a.R == b.R && a.r < b.r);
}
// 最長増加部分列 (LIS) を求めるための関数
int LIS(const vector<int> &seq) {
vector<int> lis;
for(int x : seq) {
auto it = lower_bound(lis.begin(), lis.end(), x);
if(it == lis.end()) {
lis.push_back(x);
} else {
*it = x;
}
}
return lis.size();
}
int main() {
int N;
cin >> N;
vector<Matryoshka> dolls(N);
for(int i = 0; i < N; ++i) {
cin >> dolls[i].r >> dolls[i].R;
}
// 外径でソートする
sort(dolls.begin(), dolls.end(), compare);
// 内径の配列を作成する
vector<int> innerDiameters(N);
for(int i = 0; i < N; ++i) {
innerDiameters[i] = dolls[i].r;
}
// 内径に基づいてLISを求める
int maxDolls = LIS(innerDiameters);
// 必要な操作Bの回数
int operationsB = N - maxDolls;
cout << operationsB << endl;
return 0;
}
Moss_Local