結果
問題 | No.1192 半部分列 |
ユーザー | define |
提出日時 | 2020-08-05 14:22:28 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 21 ms / 2,000 ms |
コード長 | 1,365 bytes |
コンパイル時間 | 2,069 ms |
コンパイル使用メモリ | 200,976 KB |
実行使用メモリ | 45,136 KB |
最終ジャッジ日時 | 2023-10-14 23:32:33 |
合計ジャッジ時間 | 3,359 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,460 KB |
testcase_01 | AC | 2 ms
5,424 KB |
testcase_02 | AC | 1 ms
5,416 KB |
testcase_03 | AC | 2 ms
5,416 KB |
testcase_04 | AC | 1 ms
5,548 KB |
testcase_05 | AC | 2 ms
5,412 KB |
testcase_06 | AC | 21 ms
44,956 KB |
testcase_07 | AC | 18 ms
44,960 KB |
testcase_08 | AC | 18 ms
44,904 KB |
testcase_09 | AC | 17 ms
44,700 KB |
testcase_10 | AC | 2 ms
5,472 KB |
testcase_11 | AC | 2 ms
5,548 KB |
testcase_12 | AC | 18 ms
45,136 KB |
testcase_13 | AC | 9 ms
25,456 KB |
testcase_14 | AC | 12 ms
33,772 KB |
testcase_15 | AC | 11 ms
29,812 KB |
testcase_16 | AC | 8 ms
23,716 KB |
testcase_17 | AC | 12 ms
31,976 KB |
testcase_18 | AC | 2 ms
5,480 KB |
testcase_19 | AC | 5 ms
15,044 KB |
testcase_20 | AC | 2 ms
5,484 KB |
testcase_21 | AC | 9 ms
25,204 KB |
testcase_22 | AC | 2 ms
5,912 KB |
testcase_23 | AC | 17 ms
44,836 KB |
testcase_24 | AC | 5 ms
12,920 KB |
testcase_25 | AC | 9 ms
23,152 KB |
testcase_26 | AC | 8 ms
23,252 KB |
testcase_27 | AC | 9 ms
27,780 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; #define int long long #define rep(i,n) for(int i=0;i<n;i++) #define REP(i,n) for(int i=1;i<n;i++) #define rev(i,n) for(int i=n-1;i>=0;i--) #define all(v) v.begin(),v.end() #define P pair<int,int> #define len(s) (int)s.size() template<class T> inline bool chmin(T &a, T b){ if(a>b){a=b;return true;} return false; } template<class T> inline bool chmax(T &a, T b){ if(a<b){a=b;return true;} return false; } constexpr int mod = 1e9+7; constexpr int inf = 3e18; string S,T; int nexS[100005][26],nexT[100005][26]; int inc[100005]; signed main(){ cin>>S>>T; assert(len(S)<=100000&&len(T)<=100000); rep(i,26){ nexS[len(S)][i]=len(S); nexT[len(T)][i]=len(T); } rev(i,len(S)){ rep(j,26)nexS[i][j]=nexS[i+1][j]; nexS[i][S[i]-'a']=i; } rev(i,len(T)){ rep(j,26)nexT[i][j]=nexT[i+1][j]; nexT[i][T[i]-'a']=i; } int now=len(T);inc[len(S)]=now; rev(i,len(S)){ now=max(-1ll,now-1); while(now>=0&&T[now]!=S[i])now--; inc[i]=now; } if(inc[0]!=-1){ cout<<"-1\n";return 0; } string Ans; int curS=0,curT=0; while(curS<len(S)){ rep(i,26){ if(nexS[curS][i]==len(S))continue; if(nexT[curT][i]==len(T)){ Ans+=('a'+i); cout<<Ans<<endl;return 0; } if(inc[nexS[curS][i]+1]>=nexT[curT][i]+1)continue; curS=nexS[curS][i]+1; curT=nexT[curT][i]+1; Ans+=('a'+i); break; } } }