Official

C - Vertical Reading Editorial by MtSaka


ありえるすべての \(c,w\) を全てシミュレーションし、条件を満たすような \(c,w\) が存在するか判定すればよいです。

for文および文字列の連結操作を用いることである \(c,w\) に対する文字列を作ることができます。詳細は実装例をご参照ください。

実装例(C++):

#include <bits/stdc++.h>
using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    for (int w = 1; w < (int)s.size(); ++w) {
        for (int c = 0; c < w; ++c) {
            string now = "";
            for (int i = c; i < (int)s.size(); i += w) {
                now += s[i];
            }
            if (now == t) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

posted:
last update: