結果
| 問題 | No.1909 Detect from Substrings | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2022-04-22 22:23:09 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,588 bytes | 
| コンパイル時間 | 2,716 ms | 
| コンパイル使用メモリ | 207,672 KB | 
| 最終ジャッジ日時 | 2025-01-28 20:24:15 | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 10 WA * 26 | 
ソースコード
#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;
            rep(i, N) {
                if (i == ind) continue;
                int sij = j;
                for (int k = j + 1; k < M; k++) {
                    if (S[i][k] == S[ind][sij]) sij++;
                }
                if (sij >= M - 1) continue;
                ok = 0;
                break;
            }
            ans += ok;
        }
        cout << ans << '\n';
        return 0;
    }
    return 0;
}
            
            
            
        