結果
| 問題 |
No.1609 String Division Machine
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-16 23:07:32 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 10 ms / 2,000 ms |
| コード長 | 797 bytes |
| コンパイル時間 | 681 ms |
| コンパイル使用メモリ | 69,200 KB |
| 実行使用メモリ | 13,788 KB |
| 最終ジャッジ日時 | 2024-07-06 10:38:31 |
| 合計ジャッジ時間 | 2,016 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 37 |
ソースコード
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int d[100009][26];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
string s; cin >> s;
int n = s.length();
s = " " + s;
for (int i = n; i >= 1; i--) {
for (int j = 0; j < 26; j++)
d[i][j] = d[i + 1][j];
if (s[i] == '?') continue;
int t = (int)(s[i] - 'a');
int mx = 0;
for (int j = t + 1; j < 26; j++)
mx = max(mx, d[i][j]);
d[i][t] = max(d[i][t], mx + 1);
}
int p = 0;
for (int i = 0; i < 26; i++)
p = max(p, d[1][i]);
if (!p) p = 1;
for (int i = 1; i <= n; i++) {
if (s[i] != '?') continue;
int mx = 0, r = 26;
for (int j = 25; j >= 0 && mx < p; j--) {
mx = max(mx, d[i][j]);
r = j;
}
s[i] = (char)('a' + r);
}
cout << s.substr(1, n) << '\n';
return 0;
}