提出 #76068005
ソースコード 拡げる
#include<bits/stdc++.h>
using namespace std;
const int N=3e5+10;
int T,n,cnt[30],mx;
string s;
typedef pair<int,char> PI;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>T;
while(T--){
cin>>s;
for(int i=0;i<=26;i++)cnt[i]=0;
mx=0;
for(int i=0;i<s.size();i++)cnt[s[i]-'a'+1]++;
n=s.size();
priority_queue<PI>q;
for(int i=1;i<=26;i++){
mx=max(mx,cnt[i]);
if(cnt[i]>0)q.emplace(cnt[i],'a'+i-1);//
}
if(mx>(n+1)/2){
cout<<"No\n";
continue;
}
string ans;
ans.reserve(n);
while(!q.empty()){
int cnt1=q.top().first;
char c1=q.top().second;
q.pop();
ans+=c1;
if(q.size()){
int cnt2=q.top().first;
char c2=q.top().second;
q.pop();
ans+=c2;
if(cnt2>1)q.push({cnt2-1,c2});
}
if(cnt1>1)q.push({cnt1-1,c1});
}
cout<<"Yes\n";
cout<<ans<<"\n";
}
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | D - Adjacent Distinct String |
| ユーザ | Axiom_ |
| 言語 | C++23 (GCC 15.2.0) |
| 得点 | 400 |
| コード長 | 897 Byte |
| 結果 | AC |
| 実行時間 | 41 ms |
| メモリ | 5560 KiB |
コンパイルエラー
./Main.cpp: In function 'int main()':
./Main.cpp:15:30: 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++)cnt[s[i]-'a'+1]++;
| ~^~~~~~~~~
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 400 / 400 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| 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 | 3524 KiB |
| 01_handmade_00.txt | AC | 41 ms | 3580 KiB |
| 01_handmade_01.txt | AC | 16 ms | 3516 KiB |
| 01_handmade_02.txt | AC | 4 ms | 4432 KiB |
| 01_handmade_03.txt | AC | 6 ms | 5468 KiB |
| 01_handmade_04.txt | AC | 7 ms | 5392 KiB |
| 01_handmade_05.txt | AC | 5 ms | 3536 KiB |
| 02_random_00.txt | AC | 26 ms | 5560 KiB |
| 02_random_01.txt | AC | 26 ms | 5512 KiB |
| 02_random_02.txt | AC | 26 ms | 5412 KiB |
| 02_random_03.txt | AC | 3 ms | 4316 KiB |
| 02_random_04.txt | AC | 3 ms | 4320 KiB |
| 02_random_05.txt | AC | 3 ms | 4536 KiB |
| 02_random_06.txt | AC | 3 ms | 4380 KiB |
| 02_random_07.txt | AC | 14 ms | 5468 KiB |
| 02_random_08.txt | AC | 11 ms | 3524 KiB |
| 02_random_09.txt | AC | 9 ms | 3600 KiB |
| 02_random_10.txt | AC | 7 ms | 3536 KiB |
| 02_random_11.txt | AC | 7 ms | 3460 KiB |
| 02_random_12.txt | AC | 7 ms | 3728 KiB |
| 02_random_13.txt | AC | 7 ms | 3736 KiB |