PILAME杯2024 予選問12の解説がインターネットのどこにも見当たらないので作問者が自分で解説します。
aaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
aabbbbbbbbbbbbbbaaaaaaaaabbbbbbbbbbbbbbb
abbbbbbbbbbbbaaaaaaaaaaaaaaabbbbbbbbbbbb
bbbbbbbbbbbaaaaaaaaaaaaaaaaaaabbbbbbabbb
bbbbbbbbbaaaaaaaaaaaaaaaaaaaaaabbbaaaaab
bbbbbbbbaaaaaaaaaaaaaaaaaaababaabbbaaabb
bbbbbbbaaaaaaaaaaaaaaaaaaababababbbaaabb
bbbbbbaaaaaaaaaaaaaaaaaaaabbbbbabbabbbab
bbbbbaaaaaaaaaaaaaaaaaabaaabbbaabbbbbbbb
bbbbaaaaaaaaaaaaaaaaaaabbaaaaaaabbbbbbbb
bbbbaaaaaaaaaaaaaaaaaaabbbaaaaaaabbbbbbb
bbbbaaaaaaaabaaaabaaaaabbbbaaaaaabbbbbbb
bbbbaaaaaaaabbaaabbaaabbbbbaaaaaabbbbbbb
bbbbaaaaaaaabbaaabbbaabbbbbaaaaaabbbbbbb
bbbbaaaaaaaabaaaabbbbabaaabaaaaaaabbbbbb
bbbbaaaaaaaaabbabbbbbbbabbabaaaaaabbbbbb
bbbbaaaaaabbabaabbbbbbbaababaaaaaabbbbbb
bbbbaaaaaabbabaabbbbbbbaababaaaaaaabbbbb
bbbbaaaaaabbabaabbbbbbbaabababbbaaabbbbb
bbbbaaaaaaabbbbbbbbbbbbbbbbbaaaaaaaabbbb
bbbbabaaaaabbbbbbbbbbbbbbbbbabbbaaaabbbb
bbbbabaaaaaabbbbbbbbbbbbbbbaabbbaaaabbbb
bbbbabaaaaaabbbbbbbbbbbbbbbaabbbaaaabbbb
bbbbabaaaaaabbbbbbaaaabbbbaaabbbaaaabbbb
bbbbbabaaaaaabbbbbaaaabbbbaaaaaaaaaabbbb
bbbbbbbaaaaaaaabbbbaabbbbaaaabbbaaaaabbb
bbbbbbbaaaaaaaaaabbbbbbaaaaaaaaaaaaaaabb
bbbbbbbaaaaaaaaaaaabbbaaaaaabaaaaaaaaaab
bbbbbbbaaaaaaaaaaabaaabaaaaabaaabaaaaaaa
bbbbbbaaaaaaaaaaaabbbbbaaaaabaaabaaaaaaa
bbbbbaaaaaaaaaaaaabbbbbaaaaaaaabbaaaaaaa
bbbbaaabaabbaaaaaaabbbaaaaaaaaabbaaabaaa
bbaaaabaaaaaaaaabbbaaabbbaaaaaaaaaaabbaa
aaaabbaaabaabbbbbbbbabbbbbbbaaaaaaaabbbb
bbbbbaaabaabbbbbbbbaabbbbbbbaaabbbaabbbb
bbbbaaabaabbbbbbbbaabbbbbbbaaabbbbbabbbb
bbaaabbaabbbbbbbbaabbbbbbbbaaabbbbbbabbb
aaaaabbabbbbbbbbaabbbbbbbbaaaabbbbbababb
bbabbaaabbbbbbbbabbbbbbbbbaaabbaababbbab
babbbbabbbbbbbbbabbbbbbbbaaabbaababbbbba
正整数
この時、各