結果
| 問題 |
No.2226 Hello, Forgotten World!
|
| コンテスト | |
| ユーザー |
ID 21712
|
| 提出日時 | 2025-05-08 01:16:30 |
| 言語 | Go (1.23.4) |
| 結果 |
AC
|
| 実行時間 | 195 ms / 2,000 ms |
| コード長 | 1,463 bytes |
| コンパイル時間 | 11,139 ms |
| コンパイル使用メモリ | 242,596 KB |
| 実行使用メモリ | 8,376 KB |
| 最終ジャッジ日時 | 2025-05-08 01:16:44 |
| 合計ジャッジ時間 | 14,142 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 |
ソースコード
package main
import . "fmt"
import . "strings"
import . "sort"
import "math/rand"
func main() {
var t int
Scan(&t)
for ; t > 0; t-- {
var n int
var s string
Scan(&n,&s)
Println(solve(n, s))
}
}
const H = "helloworld"
var bh = []byte(H)
func solve(n int, s string) string {
if Contains(s, H) {
return ReplaceAll(s, "?", "a")
}
b := []byte(s)
ans := []string{}
for i := len(b)-len(bh); i >= 0; i-- {
ok := true
for j, ch := range bh {
if b[i+j] != '?' && b[i+j] != ch {
ok = false
break
}
}
// コーナーケース
// h??????????
// h??l???????
// h?????????d
// h??l??????d
// helloworl?elloworld
// WA hhelloworld
// AC helloworlda
// AC helloworldd
if ok && i > 0 && b[i-1] == 'h' {
w := string(b[i:i+len(bh)-1])
ok = w != "?????????" && w != "??l??????"
}
if ok {
x := []byte(s)
for j, ch := range bh {
x[i+j] = ch
}
ans = append(ans, ReplaceAll(string(x), "?", "a"))
if len(ans) > 1 {
break
}
}
}
if len(ans) > 0 {
tmp := ans[0]
Strings(ans)
if tmp != ans[0] {
println(s)
println(tmp)
println(ans[0])
// panic("bug")
}
return ans[0]
}
return "-1"
}
func init() {
check()
}
func check() {
for t := 0; t < 50000; t++ {
n := rand.Intn(40)+30
b := make([]byte, n)
for i := range b {
c := rand.Intn(120)
if c < 26 {
b[i] = bh[rand.Intn(len(bh))]
} else {
b[i] = '?'
}
}
s := string(b)
solve(n, s)
}
}
ID 21712