提出 #76062493


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
int main() {
    int T;
    cin >> T;
    for (int i = 0; i < T; i++) {
      string S;
      cin >> S;
      int Ssize = S.size();
      vector<int> cnt(26, 0);
    for (char c : S) cnt[c-'a']++;
    int ma = *max_element(cnt.begin(), cnt.end());
    int end = 0;
    int alpha = 0;
    for (int i = 0; i < 26; i++) {
      if (cnt.at(i) == ma && end == 0) {
       alpha = i;
        end = 1;
      }
    }
    end = 0;
    if (ma > (Ssize+1)/2) {
      cout << "No" << endl;
    }
    else {
      cout << "Yes" << endl;
      bool soldout = false;
      for (int i = 0; i < Ssize; i++) {
        if (cnt.at(alpha) == 0) {
          soldout = true;
        }
        if (i % 2 == 0 && (!soldout)) {
          cout << char('a'+alpha);
          cnt.at(alpha)--;
        }
        else {
          int endend = 0;
          for (int j = 0; j < 26; j++) {
            if (!soldout && (j == alpha)) {
              continue;
            }
            if (cnt.at(j) != 0 && endend == 0) {
              cout << char('a'+j);
              cnt.at(j)--;
              endend = 1;
            }
          }
        }
      }
      cout << endl;
    }
    
    }
    return 0;
  }

提出情報

提出日時
問題 D - Adjacent Distinct String
ユーザ KOJIKEE
言語 C++23 (GCC 15.2.0)
得点 0
コード長 1273 Byte
結果 WA
実行時間 254 ms
メモリ 5432 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 400
結果
AC × 1
AC × 9
WA × 12
セット名 テストケース
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3640 KiB
01_handmade_00.txt AC 254 ms 3412 KiB
01_handmade_01.txt WA 90 ms 3540 KiB
01_handmade_02.txt AC 14 ms 5288 KiB
01_handmade_03.txt AC 32 ms 5304 KiB
01_handmade_04.txt AC 32 ms 5308 KiB
01_handmade_05.txt WA 23 ms 3536 KiB
02_random_00.txt WA 42 ms 5308 KiB
02_random_01.txt WA 42 ms 5392 KiB
02_random_02.txt WA 42 ms 5432 KiB
02_random_03.txt AC 13 ms 5284 KiB
02_random_04.txt AC 13 ms 5388 KiB
02_random_05.txt AC 13 ms 5432 KiB
02_random_06.txt AC 13 ms 5380 KiB
02_random_07.txt WA 35 ms 5376 KiB
02_random_08.txt WA 32 ms 3456 KiB
02_random_09.txt WA 27 ms 3624 KiB
02_random_10.txt WA 23 ms 3592 KiB
02_random_11.txt WA 22 ms 3528 KiB
02_random_12.txt WA 22 ms 3600 KiB
02_random_13.txt WA 21 ms 3700 KiB