結果
問題 |
No.1804 Intersection of LIS
|
ユーザー |
![]() |
提出日時 | 2025-10-09 09:55:21 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,790 bytes |
コンパイル時間 | 2,561 ms |
コンパイル使用メモリ | 208,724 KB |
実行使用メモリ | 36,768 KB |
最終ジャッジ日時 | 2025-10-09 09:55:39 |
合計ジャッジ時間 | 15,783 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 2 |
other | AC * 5 WA * 32 |
ソースコード
#include<bits/stdc++.h> using namespace std; #define REP(x,y)for(ll x=0;x<ll(y);++x) #define rep(x,y,z)for(ll x=ll(y);x<ll(z);++x) #define PER(x,y)for(ll x=ll(y)-1;x>=0;--x) #define per(x,y,z)for(ll x=ll(z)-1;x>=ll(y);--x) #define all(v)v.begin(),v.end() #define rall(v)v.rbegin(),v.rend() #define pb emplace_back #define fi first #define se second #define lb(v,k)ll(lower_bound(all(v),k)-v.begin()) #define ub(v,k)ll(upper_bound(all(v),k)-v.begin()) #define uniq(v)sort(all(v)),v.erase(unique(all(v)),v.end()) #define sz(x)ll(x.size()) #define out(x)cout<<(x)<<'\n' #define sor(v)sort(all(v)) using ll=long long; using P=pair<ll,ll>; using PP=tuple<ll,ll,ll>; using PPP=tuple<ll,ll,ll,ll>; using vi=vector<ll>; using vvi=vector<vi>; using vb=vector<bool>; using vvb=vector<vb>; using vp=vector<P>; using vvp=vector<vp>; struct $_${$_$(){ios::sync_with_stdio(false);cin.tie(nullptr);}}$_$_$; template<class T,class S>inline bool chmin(T&A,S B){if(A>B){A=B;return true;}return false;} template<class T,class S>inline bool chmax(T&A,S B){if(A<B){A=B;return true;}return false;} vi minlis(vi P) { int N=sz(P); vi dp(N,N+1); map<int,int>prv; REP(i,N) { int id=lb(dp,P[i]); if(id)prv[P[i]]=dp[id-1]; dp[id]=P[i]; } vi lis; PER(i,N)if(dp[i]<N+1) { int x=dp[i]; REP(j,i) { lis.pb(x); x=prv[x]; } lis.pb(x); break; } reverse(all(lis)); return lis; } vi maxlis(vi P) { reverse(all(P)); REP(i,sz(P))P[i]*=-1; auto Q=minlis(P); reverse(all(Q)); REP(i,sz(Q))Q[i]*=-1; return Q; } void unsolve() { int N; cin>>N; vi P(N); REP(i,N)cin>>P[i]; auto A=minlis(P); auto B=maxlis(P); vi ans; REP(i,sz(A))if(A[i]==B[i])ans.pb(P[i]); out(sz(ans)); REP(i,sz(ans))cout<<ans[i]<<" \n"[i==sz(ans)-1]; } int main() { int T=1; //cin>>T; while(T--) unsolve(); }