結果

問題 No.2629 A replace B replace C
ユーザー tnakao0123
提出日時 2024-02-17 01:49:12
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 878 bytes
コンパイル時間 341 ms
コンパイル使用メモリ 41,800 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-09-28 23:26:58
合計ジャッジ時間 2,162 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 61
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2629.cc:  No.2629 A replace B replace C - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

/* global variables */

char s[MAX_N + 4], t[MAX_N + 4];
int scs[3], tcs[3];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d%s%s", &n, s, t);

  for (int i = 0; i < n; i++) scs[s[i] - 'A']++;
  for (int i = 0; i < n; i++) tcs[t[i] - 'A']++;

  if (scs[0] >= tcs[0] && scs[1] == tcs[1]) {
    int ab = 0, bc = 0, ac = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] > t[i]) { puts("No"); return 0; }
      if (s[i] == 'A' && t[i] == 'B') ab++;
      else if (s[i] == 'B' && t[i] == 'C') bc++;
      else if (s[i] == 'A' && t[i] == 'C') ac++;
    }

    if (ab == bc && (ac == 0 || ab > 0)) { puts("Yes"); return 0; }
  }

  puts("No");
  return 0;
}
0