結果
問題 |
No.2226 Hello, Forgotten World!
|
ユーザー |
![]() |
提出日時 | 2025-05-08 00:50:07 |
言語 | Go (1.23.4) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,295 bytes |
コンパイル時間 | 12,128 ms |
コンパイル使用メモリ | 248,976 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-05-08 00:50:21 |
合計ジャッジ時間 | 12,122 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' && Count(string(b[i:i+len(bh)]), "?") == len(bh) { 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 { tmp := ans[0] Strings(ans) if tmp != ans[0] { println(tmp) println(ans[0]) panic("bug") } return ans[0] } return "-1" } func init() { // check() } func check() { for t := 0; t < 1000; 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) } }