結果

問題 No.1909 Detect from Substrings
ユーザー icchiposticchipost
提出日時 2022-04-22 22:20:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 888 bytes
コンパイル時間 1,697 ms
コンパイル使用メモリ 174,256 KB
実行使用メモリ 5,396 KB
最終ジャッジ日時 2023-09-06 08:54:15
合計ジャッジ時間 4,226 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 11 ms
4,380 KB
testcase_06 AC 22 ms
5,344 KB
testcase_07 AC 21 ms
5,280 KB
testcase_08 AC 22 ms
5,160 KB
testcase_09 AC 22 ms
5,296 KB
testcase_10 AC 21 ms
4,380 KB
testcase_11 AC 22 ms
4,380 KB
testcase_12 AC 20 ms
4,484 KB
testcase_13 AC 23 ms
5,308 KB
testcase_14 AC 22 ms
5,196 KB
testcase_15 AC 22 ms
5,092 KB
testcase_16 AC 21 ms
4,440 KB
testcase_17 AC 20 ms
4,588 KB
testcase_18 AC 22 ms
5,100 KB
testcase_19 AC 22 ms
5,344 KB
testcase_20 AC 22 ms
5,308 KB
testcase_21 AC 21 ms
5,384 KB
testcase_22 AC 22 ms
5,340 KB
testcase_23 AC 21 ms
4,564 KB
testcase_24 AC 21 ms
4,524 KB
testcase_25 AC 21 ms
4,380 KB
testcase_26 AC 22 ms
5,092 KB
testcase_27 AC 22 ms
5,084 KB
testcase_28 AC 22 ms
5,088 KB
testcase_29 AC 21 ms
5,156 KB
testcase_30 AC 22 ms
5,396 KB
testcase_31 AC 22 ms
5,196 KB
testcase_32 AC 22 ms
5,340 KB
testcase_33 AC 22 ms
5,136 KB
testcase_34 AC 22 ms
5,132 KB
testcase_35 AC 22 ms
5,100 KB
testcase_36 AC 21 ms
5,088 KB
testcase_37 AC 22 ms
5,148 KB
testcase_38 AC 22 ms
5,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using pii = pair<int, int>;
using ll = long long;

int main() {
	int n, m;
	cin >> n >> m;
	vector<string> s(n);
	rep(i, n) cin >> s[i];
	sort(s.begin(), s.end());

	rep(j, m) {
		char c = s[0][j];
		bool ok = true;
		rep(i, n) if (s[i][j] != c) ok = false;
		if (!ok) {
			rep(i, n) {
				s[i] = s[i].substr(j);
			}
			m -= j;
			break;
		}
	}

	bool ok1 = true;
	bool ok2 = true;
	string t = s[0][0] + s[n - 1];
	string u = s[n - 1][0] + s[0];
	rep(i, n) {
		int ti = 0;
		rep(si, m) {
			if (s[i][si] == t[ti]) ti++;
			else ti += 2;
			if (ti > m + 1) {
				ok1 = false;
				break;
			}
		}

		int ui = 0;
		rep(si, m) {
			if (s[i][si] == u[ui]) ui++;
			else ui += 2;
			if (ui > m + 1) {
				ok2 = false;
				break;
			}
		}
	}

	int ans = ok1 + ok2;
	cout << ans << endl;
	return 0;
}
0