結果

問題 No.1909 Detect from Substrings
ユーザー ruthenruthen
提出日時 2022-04-22 22:27:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 1,646 bytes
コンパイル時間 2,176 ms
コンパイル使用メモリ 213,732 KB
実行使用メモリ 4,512 KB
最終ジャッジ日時 2023-09-06 09:01:34
合計ジャッジ時間 4,199 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 5 ms
4,424 KB
testcase_07 AC 5 ms
4,484 KB
testcase_08 AC 14 ms
4,380 KB
testcase_09 AC 8 ms
4,380 KB
testcase_10 AC 6 ms
4,464 KB
testcase_11 AC 7 ms
4,380 KB
testcase_12 AC 6 ms
4,380 KB
testcase_13 AC 8 ms
4,404 KB
testcase_14 AC 11 ms
4,380 KB
testcase_15 AC 12 ms
4,380 KB
testcase_16 AC 7 ms
4,376 KB
testcase_17 AC 7 ms
4,500 KB
testcase_18 AC 7 ms
4,376 KB
testcase_19 AC 7 ms
4,476 KB
testcase_20 AC 7 ms
4,428 KB
testcase_21 AC 12 ms
4,500 KB
testcase_22 AC 14 ms
4,468 KB
testcase_23 AC 7 ms
4,376 KB
testcase_24 AC 7 ms
4,376 KB
testcase_25 AC 7 ms
4,392 KB
testcase_26 AC 13 ms
4,380 KB
testcase_27 AC 13 ms
4,504 KB
testcase_28 AC 11 ms
4,380 KB
testcase_29 AC 10 ms
4,396 KB
testcase_30 AC 13 ms
4,448 KB
testcase_31 AC 10 ms
4,376 KB
testcase_32 AC 13 ms
4,380 KB
testcase_33 AC 9 ms
4,380 KB
testcase_34 AC 13 ms
4,376 KB
testcase_35 AC 10 ms
4,380 KB
testcase_36 AC 14 ms
4,392 KB
testcase_37 AC 10 ms
4,512 KB
testcase_38 AC 13 ms
4,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#ifdef _RUTHEN
#include "debug.hpp"
#else
#define show(...) true
#endif

using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T> using V = vector<T>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M;
    cin >> N >> M;
    V<string> S(N);
    rep(i, N) cin >> S[i];
    rep(j, M) {
        set<char> st;
        rep(i, N) st.insert(S[i][j]);
        if (st.size() == 1) continue;
        if (st.size() >= 3) {
            cout << 0 << '\n';
            return 0;
        }
        map<char, int> mp;
        rep(i, N) mp[S[i][j]]++;
        show(mp);
        for (auto [c, cnt] : mp) {
            if (N - cnt > 1) {
                st.erase(c);
            }
        }
        show(st);
        int ans = 0;
        for (auto c : st) {
            int ind = -1;
            rep(i, N) {
                if (S[i][j] != c) {
                    // S[i]のj文字目以降に、他のS[i]のj+1文字目以降が含まれているかを確認する
                    ind = i;
                    break;
                }
            }
            int ok = 1;
            show(ind);
            rep(i, N) {
                if (i == ind) continue;
                int k = j + 1;
                for (int sij = j; sij < M; sij++) {
                    if (S[i][k] == S[ind][sij]) k++;
                    if (k == M) break;
                }
                if (k >= M) continue;
                ok = 0;
                break;
            }
            ans += ok;
        }
        cout << ans << '\n';
        return 0;
    }
    return 0;
}
0