結果
| 問題 |
No.2226 Hello, Forgotten World!
|
| コンテスト | |
| ユーザー |
ID 21712
|
| 提出日時 | 2025-05-08 00:44:49 |
| 言語 | Go (1.23.4) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,153 bytes |
| コンパイル時間 | 12,010 ms |
| コンパイル使用メモリ | 236,208 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-05-08 00:45:02 |
| 合計ジャッジ時間 | 12,216 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 7 WA * 2 |
ソースコード
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??????????
// WA hhelloworld
// AC helloworlda
if i > 0 && b[i-1] == 'h' {
ok = false
}
if ok {
x := []byte(s)
for j, ch := range bh {
x[i+j] = ch
}
ans = append(ans, ReplaceAll(string(x), "?", "a"))
break
}
}
if len(ans) > 0 {
Strings(ans)
return ans[0]
}
return "-1"
}
func init() {
// check()
}
func check() {
for t := 0; t < 100; t++ {
n := rand.Intn(40)+30
b := make([]byte, n)
for i := range b {
c := rand.Intn(120)
if c < 26 {
b[i] = byte(c + 'a')
} else {
b[i] = '?'
}
}
s := string(b)
solve(n, s)
}
}
ID 21712