結果

問題 No.1804 Intersection of LIS
ユーザー KudeKude
提出日時 2022-01-07 22:38:20
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 1,716 bytes
コンパイル時間 2,573 ms
コンパイル使用メモリ 227,008 KB
実行使用メモリ 14,756 KB
最終ジャッジ日時 2023-08-09 03:26:06
合計ジャッジ時間 5,949 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 64 ms
6,968 KB
testcase_04 AC 66 ms
6,984 KB
testcase_05 AC 65 ms
7,032 KB
testcase_06 AC 66 ms
6,928 KB
testcase_07 AC 66 ms
6,972 KB
testcase_08 AC 66 ms
6,940 KB
testcase_09 AC 67 ms
6,920 KB
testcase_10 AC 65 ms
6,968 KB
testcase_11 AC 67 ms
7,040 KB
testcase_12 AC 67 ms
6,944 KB
testcase_13 AC 67 ms
7,032 KB
testcase_14 AC 67 ms
7,028 KB
testcase_15 AC 66 ms
7,044 KB
testcase_16 AC 63 ms
7,036 KB
testcase_17 AC 66 ms
6,964 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1 ms
4,384 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 71 ms
14,544 KB
testcase_36 AC 71 ms
14,756 KB
testcase_37 AC 30 ms
6,740 KB
testcase_38 AC 31 ms
6,696 KB
testcase_39 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic pop
using namespace std;
using namespace atcoder;
#define rep(i,n)for (int i = 0; i < int(n); ++i)
#define rrep(i,n)for (int i = int(n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) { a = max(a, b); }
template<class T> void chmin(T& a, const T& b) { a = min(a, b); }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VI p(n);
  rep(i, n) cin >> p[i], p[i]--;
  VI pre1(n);
  VI d1;
  for(int x : p) {
    int pos = lower_bound(all(d1), x) - d1.begin();
    pre1[x] = pos ? d1[pos - 1] : -1;
    if (pos < d1.size()) d1[pos] = x;
    else d1.emplace_back(x);
  }
  VI lis1;
  int v = d1.back();
  while(v != -1) {
    lis1.emplace_back(v);
    v = pre1[v];
  }
  reverse(all(lis1));

  VI pre2(n);
  VI d2;
  reverse(all(p));
  for(int x : p) {
    int pos = lower_bound(all(d2), x, greater<>()) - d2.begin();
    pre2[x] = pos ? d2[pos - 1] : -1;
    if (pos < d2.size()) d2[pos] = x;
    else d2.emplace_back(x);
  }
  VI lis2;
  v = d2.back();
  while(v != -1) {
    lis2.emplace_back(v);
    v = pre2[v];
  }
  vector<char> used(n);
  for(int x : lis1) used[x] = true;
  VI ans;
  for(int x : lis2) if (used[x]) ans.emplace_back(x);
  int sz = ans.size();
  cout << sz << '\n';
  if (sz) {
    rep(i, sz) cout << ans[i] + 1 << " \n"[i + 1 == sz];
  } else {
    cout << '\n';
  }
}
0