提出 #73709053


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;

int main() {
  string s,t;
  cin >> s >> t;

  string s_rem = "", t_rem = "";
  for (int i = 0;i < s.size();i++) {
    if (s[i] != 'A')s_rem += s[i];
  }
  for (int i = 0;i < t.size();i++) {
    if (t[i] != 'A')t_rem += t[i];
  }

  if (s_rem != t_rem) {
    cout << -1 << endl;
    return 0;
  }

  int rem_size = s_rem.size();
  if (rem_size == 0) {
    cout << max(t.size(), s.size()) - min(t.size(), s.size()) << endl;
    return 0;
  }

  vector<int> s_numA(rem_size+1, 0), t_numA(rem_size+1, 0);
  // int idx = 0;
  // int prev = 0;
  // while (idx < s.size()) {
  //   while (idx < s.size()) {
  //     if (s_rem[idx] != 'A')break;
  //     idx++;
  //   }
  //   s_numA[pos] = idx - prev;
  //   pos++;
  //   prev = idx;
  //   idx++;
  // }

  int prev_notA_pos = 0;
  int pos = 0;
  while (pos < rem_size+1) {
    int next_notA_pos = prev_notA_pos;
    while (next_notA_pos < s.size()) {
      if (s[next_notA_pos] != 'A')break;
      next_notA_pos++;
    }
    s_numA[pos] = next_notA_pos - prev_notA_pos;
    pos++;
    prev_notA_pos = next_notA_pos+1;
  }

  prev_notA_pos = 0;
  pos = 0;
  while (pos < rem_size+1) {
    int next_notA_pos = prev_notA_pos;
    while (next_notA_pos < t.size()) {
      if (t[next_notA_pos] != 'A')break;
      next_notA_pos++;
    }
    // printf("next_notA_pos:%d, prev_notA_pos:%d\n", next_notA_pos, prev_notA_pos);
    t_numA[pos] = next_notA_pos - prev_notA_pos;
    pos++;
    prev_notA_pos = next_notA_pos+1;
  }

  int ans = 0;
  for (int i = 0;i < rem_size+1;i++) {
    // printf("s_rem[%d]:%d\n", i, s_numA[i]);
    // printf("t_rem[%d]:%d\n", i, t_numA[i]);
    ans += abs(t_numA[i] - s_numA[i]);
  }

  cout << ans << endl;
}

提出情報

提出日時
問題 C - Insert and Erase A
ユーザ knr_imtr
言語 C++23 (GCC 15.2.0)
得点 300
コード長 1805 Byte
結果 AC
実行時間 12 ms
メモリ 6880 KiB

コンパイルエラー

./Main.cpp: In function 'int main()':
./Main.cpp:9:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |   for (int i = 0;i < s.size();i++) {
      |                  ~~^~~~~~~~~~
./Main.cpp:12:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |   for (int i = 0;i < t.size();i++) {
      |                  ~~^~~~~~~~~~
./Main.cpp:45:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     while (next_notA_pos < s.size()) {
      |            ~~~~~~~~~~~~~~^~~~~~~~~~
./Main.cpp:58:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     while (next_notA_pos < t.size()) {
      |            ~~~~~~~~~~~~~~^~~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 4
AC × 33
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 02_random2_06.txt, 02_random2_07.txt, 02_random2_08.txt, 02_random2_09.txt, 02_random2_10.txt, 02_random2_11.txt, 03_random3_00.txt, 03_random3_01.txt, 03_random3_02.txt, 03_random3_03.txt, 04_handmade_00.txt, 04_handmade_01.txt, 04_handmade_02.txt, 04_handmade_03.txt, 04_handmade_04.txt, 04_handmade_05.txt, 04_handmade_06.txt, 04_handmade_07.txt, 04_handmade_08.txt, 04_handmade_09.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3416 KiB
00_sample_01.txt AC 1 ms 3556 KiB
00_sample_02.txt AC 1 ms 3576 KiB
00_sample_03.txt AC 1 ms 3476 KiB
01_random_00.txt AC 2 ms 3632 KiB
01_random_01.txt AC 4 ms 3912 KiB
01_random_02.txt AC 9 ms 4816 KiB
02_random2_00.txt AC 7 ms 5832 KiB
02_random2_01.txt AC 9 ms 4296 KiB
02_random2_02.txt AC 11 ms 6476 KiB
02_random2_03.txt AC 12 ms 6348 KiB
02_random2_04.txt AC 9 ms 5496 KiB
02_random2_05.txt AC 6 ms 4396 KiB
02_random2_06.txt AC 9 ms 5984 KiB
02_random2_07.txt AC 6 ms 4152 KiB
02_random2_08.txt AC 10 ms 4792 KiB
02_random2_09.txt AC 11 ms 5036 KiB
02_random2_10.txt AC 8 ms 6032 KiB
02_random2_11.txt AC 10 ms 6668 KiB
03_random3_00.txt AC 8 ms 4804 KiB
03_random3_01.txt AC 7 ms 4160 KiB
03_random3_02.txt AC 7 ms 4480 KiB
03_random3_03.txt AC 8 ms 4328 KiB
04_handmade_00.txt AC 1 ms 3304 KiB
04_handmade_01.txt AC 1 ms 3568 KiB
04_handmade_02.txt AC 1 ms 3536 KiB
04_handmade_03.txt AC 1 ms 3532 KiB
04_handmade_04.txt AC 10 ms 6880 KiB
04_handmade_05.txt AC 8 ms 4668 KiB
04_handmade_06.txt AC 8 ms 4568 KiB
04_handmade_07.txt AC 8 ms 4384 KiB
04_handmade_08.txt AC 4 ms 3984 KiB
04_handmade_09.txt AC 4 ms 3852 KiB