結果

問題 No.3746 Swap and LIS
コンテスト
ユーザー GOTKAKO
提出日時 2026-09-25 21:53:55
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 58 ms / 2,000 ms
+ 296µs
コード長 955 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,334 ms
コンパイル使用メモリ 215,616 KB
実行使用メモリ 9,868 KB
最終ジャッジ日時 2026-09-25 21:54:01
合計ジャッジ時間 5,701 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
 
    int T; cin >> T;
    while(T--){
        int N; cin >> N;
        vector<int> A(N),B(N);
        for(auto &a : A) cin >> a;
        for(auto &a : B) cin >> a;

        vector<int> dp1(N+1,1001001001),dp2(N+1,1001001001);
        auto add = [&](int x) -> void {
            int pos = lower_bound(dp1.begin(),dp1.end(),x)-dp1.begin();
            if(dp1.at(pos) != 1001001001){
                int pos2 = lower_bound(dp2.begin(),dp2.end(),dp1.at(pos))-dp2.begin();
                dp2.at(pos2) = dp1.at(pos);
            }
            dp1.at(pos) = x;
        };
        for(int i=0; i<N; i++) add(max(A.at(i),B.at(i))),add(min(A.at(i),B.at(i)));
        

        int answer = 0;
        for(auto d : dp1) if(d != 1001001001) answer++;
        for(auto d : dp2) if(d != 1001001001) answer++;
        cout << answer << "\n";
    }
}
0