提出 #76052493


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
int cnt[27];
struct node {
    char c; int x;
    bool operator < (const node& y) const {
        return x < y.x;
    }
};
priority_queue<node> pq;
int main() {
    int T; cin >> T; while(T--) {
        string s; cin >> s; int mx = 0;
        for(int i = 0;i <= 26;i++) cnt[i] = 0;
        for(int i = 0;i < s.size();i++)
            mx = max(mx, ++cnt[s[i] - 'a']);
        int can = s.size() / 2 + s.size() % 2;
        cout << (mx <= can ? "Yes" : "No") << endl;
        if(mx > can) continue; int n = s.size();
        while(!pq.empty()) pq.pop();
        for(int i = 0;i < 26;i++)
            if(cnt[i]) pq.push({char('a' + i), cnt[i]});
        while(pq.size() > 1) {
            node u = pq.top(); pq.pop();
            node v = pq.top(); pq.pop();
            cout << u.c << v.c; u.x--; v.x--;
            if(u.x) pq.push(u); if(v.x) pq.push(v);
        } if(!pq.empty()) {
            node _ = pq.top();
            while(_.x) cout << _.c, _.x--; 
        } cout << endl;
    }
    return 0;       
}

提出情報

提出日時
問題 D - Adjacent Distinct String
ユーザ Eason_cyx
言語 C++23 (GCC 15.2.0)
得点 400
コード長 1088 Byte
結果 AC
実行時間 226 ms
メモリ 5500 KiB

コンパイルエラー

./Main.cpp: In function 'int main()':
./Main.cpp:15:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |         for(int i = 0;i < s.size();i++)
      |                       ~~^~~~~~~~~~
./Main.cpp:19:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   19 |         if(mx > can) continue; int n = s.size();
      |         ^~
./Main.cpp:19:32: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   19 |         if(mx > can) continue; int n = s.size();
      |                                ^~~
./Main.cpp:27:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   27 |             if(u.x) pq.push(u); if(v.x) pq.push(v);
      |             ^~
./Main.cpp:27:33: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   27 |             if(u.x) pq.push(u); if(v.x) pq.push(v);
      |                                 ^~
./Main.cpp:19:36: warning: unused variable 'n' [-Wunused-variable]
   19 |         if(mx > can) continue; int n = s.size();
      |                                    ^

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 1
AC × 21
セット名 テストケース
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 3440 KiB
01_handmade_00.txt AC 226 ms 3584 KiB
01_handmade_01.txt AC 83 ms 3620 KiB
01_handmade_02.txt AC 15 ms 5372 KiB
01_handmade_03.txt AC 23 ms 5372 KiB
01_handmade_04.txt AC 24 ms 5372 KiB
01_handmade_05.txt AC 21 ms 3472 KiB
02_random_00.txt AC 27 ms 5272 KiB
02_random_01.txt AC 27 ms 5272 KiB
02_random_02.txt AC 28 ms 5500 KiB
02_random_03.txt AC 14 ms 5392 KiB
02_random_04.txt AC 14 ms 5272 KiB
02_random_05.txt AC 14 ms 5432 KiB
02_random_06.txt AC 14 ms 5432 KiB
02_random_07.txt AC 30 ms 5340 KiB
02_random_08.txt AC 28 ms 3600 KiB
02_random_09.txt AC 24 ms 3516 KiB
02_random_10.txt AC 20 ms 3548 KiB
02_random_11.txt AC 19 ms 3440 KiB
02_random_12.txt AC 19 ms 3648 KiB
02_random_13.txt AC 18 ms 3648 KiB