結果

問題 No.1909 Detect from Substrings
ユーザー umezo
提出日時 2022-04-22 22:26:22
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,189 bytes
コンパイル時間 2,515 ms
コンパイル使用メモリ 197,636 KB
最終ジャッジ日時 2025-01-28 20:26:07
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int n,m;
  cin>>n>>m;
  vector<string> S(n);
  rep(i,n) cin>>S[i];
  
  int num=-1;
  rep(i,m){
    if(S[0][i]!=S[1][i]){
      num=i;
      break;
    }
  }
  
  string s1,s2;
  s1=S[0].substr(0,num+1)+S[1].substr(num);
  s2=S[1].substr(0,num+1)+S[0].substr(num);
  
  int cnt=0;
  bool b=true;
  rep(i,n){
    int c=0;
    rep(j,m){
      if(c==0){
        if(S[i][j]!=s1[j]){
          c=1;
          continue;
        }
      }
      else if(c==1){
        if(S[i][j]!=s1[j+1]){
          c=2;
          break;
        }
      }
    }
    if(c==2){
      b=false;
      break;
    }
  }
  if(b) cnt++;
  
  b=true;
  rep(i,n){
    int c=0;
    rep(j,m){
      if(c==0){
        if(S[i][j]!=s2[j]){
          c=1;
          continue;
        }
      }
      else if(c==1){
        if(S[i][j]!=s2[j+1]){
          c=2;
          break;
        }
      }
    }
    if(c==2){
      b=false;
      break;
    }
  }
  if(b) cnt++;
  
  cout<<cnt<<endl;
  
  return 0;
}
0