結果

問題 No.1909 Detect from Substrings
ユーザー sahiyasahiya
提出日時 2022-04-22 22:15:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,309 bytes
コンパイル時間 1,842 ms
コンパイル使用メモリ 136,624 KB
実行使用メモリ 36,848 KB
最終ジャッジ日時 2023-09-06 08:47:57
合計ジャッジ時間 10,669 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
34,588 KB
testcase_01 AC 16 ms
34,592 KB
testcase_02 AC 15 ms
34,576 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 18 ms
35,144 KB
testcase_06 AC 18 ms
35,700 KB
testcase_07 AC 17 ms
35,760 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define ALL(x) (x).begin(), (x).end()
#define PC(x) __builtin_popcount(x)
#define PCL(x) __builtin_popcountll(x)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
struct edge {
    int to, cost, id;
};
const double PI = 3.14159265358979323846;
const double PI2 = PI * 2.0;
const double EPS = 1E-09;
const ll MOD = 1E+09 + 7; // =998244353;
const ll INFL = 1E18;
const int INFI = 1E09;
const int MAX_N = 1E+06;

ll dx[4] = { -1, 1, 0, 0 }, dy[4] = { 0, 0, -1, 1 };

int N, M;

string S[MAX_N + 1];

bool solve(string t0, string t1, string& s0f, string& s0b)
{
    string m0 = t0.substr(1);
    string m1 = t1.substr(0, t1.size() - 1);
    if (m0 != m1) {
        return false;
    }
    string t = s0f + t0 + m1.back() + s0b;
    for (int i = 2; i < N; ++i) {
        if (t.find(S[i]) == string::npos)
            return false;
    }
    return true;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N >> M;

    for (int i = 0; i < N; ++i) {
        cin >> S[i];
    }

    int l = -1;
    while (S[0][l + 1] == S[1][l + 1]) {
        ++l;
    }
    int r = N;
    while (S[0][r - 1] == S[1][r - 1]) {
        --r;
    }

    string t0 = S[0].substr(l + 1, r - l - 1);
    string t1 = S[1].substr(l + 1, r - l - 1);

    int ans = 0;
    {
        string s0f = S[0].substr(0, l + 1);
        string s0b = S[0].substr(r);
        ans += solve(t0, t1, s0f, s0b);
    }
    {
        string s0f = S[1].substr(0, l + 1);
        string s0b = S[1].substr(r);
        ans += solve(t1, t0, s0f, s0b);
    }

    // for (int i = 0; i < N; i++) {
    //     for (int j = 0; j < N; j++) {
    //         cout << "i = " << i << ", j = " << j << ", dp = " << dp[i][j] << "\n";
    //     }
    // }

    cout << ans << "\n";

    return 0;
}
0