結果
| 問題 |
No.1192 半部分列
|
| コンテスト | |
| ユーザー |
e869120
|
| 提出日時 | 2021-03-05 18:54:22 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,443 bytes |
| コンパイル時間 | 844 ms |
| コンパイル使用メモリ | 85,480 KB |
| 実行使用メモリ | 24,572 KB |
| 最終ジャッジ日時 | 2024-10-06 20:54:28 |
| 合計ジャッジ時間 | 2,247 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 WA * 12 |
ソースコード
#include <iostream>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)
string S, T;
int cs[100009][26];
int ct[100009][26];
int dp[100009];
int main() {
// Step #1. 入力
cin >> S >> T;
// Step #2. S について計算
for (int i = 0; i < 26; i++) cs[S.size()][i] = S.size();
for (int i = S.size() - 1; i >= 0; i--) {
for (int j = 0; j < 26; j++) cs[i][j] = cs[i + 1][j];
cs[i][S[i] - 'a'] = i;
}
// Step #3. T について計算
for (int i = 0; i < 26; i++) ct[T.size()][i] = T.size();
for (int i = T.size() - 1; i >= 0; i--) {
for (int j = 0; j < 26; j++) ct[i][j] = ct[i + 1][j];
ct[i][T[i] - 'a'] = i;
}
// Step #4. 貪欲法
dp[S.size()] = T.size(); int cx = T.size() - 1;
for (int i = S.size() - 1; i >= 0; i--) {
while (cx >= 0 && T[cx] != S[i]) cx--;
dp[i] = cx;
}
// Step #5. 辞書順貪欲
int px = 0, qx = 0;
string str = "";
while (px < S.size()) {
bool flag = false;
for (int i = 0; i < 26; i++) {
int nex1 = cs[px][i];
int nex2 = ct[qx][i];
if (nex1 == S.size()) continue;
if (dp[nex1 + 1] < nex2 + 1) {
flag = true;
str += ('a' + i);
px = nex1 + 1;
qx = nex2 + 1;
break;
}
}
if (flag == false) break;
}
// Step #6. 出力
if (str == "") cout << "-1" << endl;
else cout << str << endl;
return 0;
}
e869120