Submission #76072384


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
int t,l,r,f,cnt[30];
string s,ans;
priority_queue<pair<int,char>> q;
int main(){
	cin>>t;
	while(t--){
		cin>>s,ans=string(s.size(),'`'),l=f=0,r=1;
		for(int i=0;i<26;i++) cnt[i]=0;
		for(int i=0;i<s.size();i++) cnt[s[i]-'a']++;
		for(int i=0;i<26;i++) if(cnt[i]) q.push({cnt[i],'a'+i});
		while(!q.empty()){
			int y=q.top().first;
			char c=q.top().second;
			q.pop();
			if(l>s.size()) for(int i=r,j=1;j<=y;i+=2,j++) ans[i]=c,r=i+2;
			else if(l+y*2>s.size()){
				int ct=0;
				for(int i=l;i<s.size();i+=2) ct++,ans[i]=c,l=i+2;
				ct=y-ct;
				for(int i=r,j=1;j<=ct;i+=2,j++) ans[i]=c,r=i+2;
			}
			else for(int i=l,j=1;j<=y;i+=2,j++) ans[i]=c,l=i+2;
		}
		if(ans[0]=='`') f=1;
		for(int i=1;i<ans.size();i++)
			if(ans[i]=='`'||ans[i]==ans[i-1]) f=1;
		if(f) cout<<"No\n";
		else cout<<"Yes\n"<<ans<<endl;
	}
}

Submission Info

Submission Time
Task D - Adjacent Distinct String
User Rya_
Language C++23 (GCC 15.2.0)
Score 400
Code Size 893 Byte
Status AC
Exec Time 161 ms
Memory 5528 KiB

Compile Error

./Main.cpp: In function 'int main()':
./Main.cpp:11:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |                 for(int i=0;i<s.size();i++) cnt[s[i]-'a']++;
      |                             ~^~~~~~~~~
./Main.cpp:17:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |                         if(l>s.size()) for(int i=r,j=1;j<=y;i+=2,j++) ans[i]=c,r=i+2;
      |                            ~^~~~~~~~~
./Main.cpp:18:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |                         else if(l+y*2>s.size()){
      |                                 ~~~~~^~~~~~~~~
./Main.cpp:20:46: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |                                 for(int i=l;i<s.size();i+=2) ct++,ans[i]=c,l=i+2;
      |                                             ~^~~~~~~~~
./Main.cpp:27:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |                 for(int i=1;i<ans.size();i++)
      |                             ~^~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 1
AC × 21
Set Name Test Cases
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
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3428 KiB
01_handmade_00.txt AC 161 ms 3384 KiB
01_handmade_01.txt AC 63 ms 3556 KiB
01_handmade_02.txt AC 18 ms 5360 KiB
01_handmade_03.txt AC 17 ms 5328 KiB
01_handmade_04.txt AC 17 ms 5268 KiB
01_handmade_05.txt AC 20 ms 3556 KiB
02_random_00.txt AC 16 ms 5460 KiB
02_random_01.txt AC 16 ms 5360 KiB
02_random_02.txt AC 16 ms 5528 KiB
02_random_03.txt AC 17 ms 5512 KiB
02_random_04.txt AC 17 ms 5352 KiB
02_random_05.txt AC 17 ms 5240 KiB
02_random_06.txt AC 17 ms 5368 KiB
02_random_07.txt AC 17 ms 5512 KiB
02_random_08.txt AC 24 ms 3528 KiB
02_random_09.txt AC 20 ms 3592 KiB
02_random_10.txt AC 17 ms 3556 KiB
02_random_11.txt AC 16 ms 3564 KiB
02_random_12.txt AC 16 ms 3564 KiB
02_random_13.txt AC 16 ms 3564 KiB