結果

問題 No.1909 Detect from Substrings
ユーザー ruthen71ruthen71
提出日時 2022-04-22 22:03:12
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,563 bytes
コンパイル時間 1,984 ms
コンパイル使用メモリ 181,960 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-24 03:16:31
合計ジャッジ時間 3,518 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 26
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:31:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   31 |         for (auto [c, cnt] : mp) {
      |                   ^

ソースコード

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]]++;
        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 || sij == M - 2) continue;
                ok = 0;
            }
            ans += ok;
        }
        cout << ans << '\n';
        return 0;
    }
    return 0;
}
0