結果

問題 No.1909 Detect from Substrings
ユーザー ruthenruthen
提出日時 2022-04-22 22:23:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,588 bytes
コンパイル時間 2,280 ms
コンパイル使用メモリ 212,540 KB
実行使用メモリ 4,572 KB
最終ジャッジ日時 2023-09-06 08:56:51
合計ジャッジ時間 3,938 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 3 ms
4,480 KB
testcase_07 AC 3 ms
4,444 KB
testcase_08 AC 14 ms
4,376 KB
testcase_09 AC 8 ms
4,508 KB
testcase_10 AC 5 ms
4,380 KB
testcase_11 AC 7 ms
4,376 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
            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;
}
0