結果

問題 No.3746 Swap and LIS
コンテスト
ユーザー ponjuice
提出日時 2026-09-14 00:04:12
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 139 ms / 2,000 ms
+ 374µs
コード長 1,100 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,034 ms
コンパイル使用メモリ 337,236 KB
実行使用メモリ 14,348 KB
最終ジャッジ日時 2026-09-25 20:52:34
合計ジャッジ時間 7,630 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i = (a); i < (b); i++)
#define all(a) (a).begin(), (a).end()
const ll inf = 2'000'000'000'000'000'000;


int main() {
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector<int> a(n),b(n);
        rep(i,0,n) cin >> a[i];
        rep(i,0,n) cin >> b[i];
        vector<ll> c(n*2);
        rep(i,0,n) {
            c[i*2] = a[i];
            c[i*2+1] = b[i];
            if(c[i*2] < c[i*2+1]) swap(c[i*2], c[i*2+1]);
        }
        rep(i,0,n*2) {
            c[i] = c[i] * 2*n + (2*n-1-i);
        }

        vector<ll> dp1(n*2, inf), dp2(n*2, inf);
        rep(i,0,n*2) {
            int pos = upper_bound(all(dp1), c[i]) - dp1.begin();
            
            ll nx = dp1[pos];
            dp1[pos] = c[i];
            
            if(nx == inf) continue;

            pos = upper_bound(all(dp2), nx) - dp2.begin();
            dp2[pos] = nx;
        }
        cout << (lower_bound(all(dp1), inf)-dp1.begin()) + (lower_bound(all(dp2), inf)-dp2.begin()) << endl;
    }
}
0