結果
| 問題 |
No.1909 Detect from Substrings
|
| コンテスト | |
| ユーザー |
Rubikun
|
| 提出日時 | 2022-04-22 21:19:50 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 44 ms / 2,000 ms |
| コード長 | 2,378 bytes |
| コンパイル時間 | 2,208 ms |
| コンパイル使用メモリ | 205,764 KB |
| 最終ジャッジ日時 | 2025-01-28 19:49:22 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=1<<30;
int main(){
std::ifstream in("text.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
int N,M;cin>>N>>M;
vector<string> S(N);
for(int i=0;i<N;i++) cin>>S[i];
string A=S[0],B=S[1];
int i=0;
while(i<M&&A[i]==B[i]) i++;
int j=M-1;
while(j>=0&&A[j]==B[j]) j--;
set<string> SE;
if(i==j){
string C=A.substr(0,i)+A[i]+B[i]+A.substr(i),D=A.substr(0,i)+B[i]+A[i]+A.substr(i);
{
bool f=true;
for(int i=0;i<N;i++){
int k=0;
for(char c:C){
if(k<si(S[i])&&S[i][k]==c) k++;
}
if(k<si(S[i])) f=false;
}
if(f) SE.insert(C);
}
{
bool f=true;
for(int i=0;i<N;i++){
int k=0;
for(char c:D){
if(k<si(S[i])&&S[i][k]==c) k++;
}
if(k<si(S[i])) f=false;
}
if(f) SE.insert(D);
}
}else{
A=A.substr(i,j-i+1);
B=B.substr(i,j-i+1);
if(A.substr(1)==B.substr(0,si(B)-1)){
string C=S[0].substr(0,i)+A+B.back()+S[0].substr(j+1);
bool f=true;
for(int i=0;i<N;i++){
int k=0;
for(char c:C){
if(k<si(S[i])&&S[i][k]==c) k++;
}
if(k<si(S[i])) f=false;
}
if(f) SE.insert(C);
}
if(B.substr(1)==A.substr(0,si(A)-1)){
string D=S[0].substr(0,i)+B+A.back()+S[0].substr(j+1);
bool f=true;
for(int i=0;i<N;i++){
int k=0;
for(char c:D){
if(k<si(S[i])&&S[i][k]==c) k++;
}
if(k<si(S[i])) f=false;
}
if(f) SE.insert(D);
}
}
cout<<si(SE)<<endl;
}
Rubikun