General

# Author Problem Lang Verdict Time Memory Sent Judged
71143726 Contestant:
thelonewolf
1304B - 22 GNU C++14 Runtime error on pretest 3 15 ms 4 KB 2020-02-15 16:46:27 2020-02-15 16:46:31

→ Source
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl "\n"
const int MAX= 100005 ;
const long long mod = 1.0e9+7;
ll ceil(ll a,ll b)
{
if(a%b==0)
{
return a/b;
}
else
{
return a/b+1;
}
}
string reverseStr(string str)
{
int n = str.length();
string t="";
// Swap character starting from two
// corners
for (int i = 0; i < n ; i++)
{
t+=str[n-i-1];
}
return t;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int n,m;
cin>>n>>m;
int i,j;
string s[n+1];
map<string,int> mp;
for(i=0;i<n;i++)
{
cin>>s[i];
mp[s[i]]++;
}
vector<string> v;
for(auto it:mp)
{
string str=it.first;
int cnt=it.second;
string t=reverseStr(str);
int cnt2=mp[t];
//cout<<str<<" "<<t<<"yy"<<endl;
if(str==t)
{
//cout<<str<<cnt<<endl;
if(cnt<2)
continue;
else
{
cnt=cnt/2;
}
}
for(i=0;i<min(cnt,cnt2);i++){
v.push_back(str);
v.push_back(t);
}
mp[str]-=min(cnt,cnt2);
mp[t]-=min(cnt,cnt2);
}
vector<string> mid;
for(auto it: mp)
{
//cout<<it.first<<" "<<it.second<<endl;
if(it.second >0 )
{
string str=it.first;
int cnt=it.second;
for(i=0;i<m;i++)
{
if(str[i]!=str[m-i-1])
break;
}
if(i==(m))
{
string tt="";
while(cnt>0)
{
tt+=str;
cnt--;
}
mid.push_back(tt);
}
}
}
int maxx=0;
string ans="";
for(i=0;i<mid.size();i++)
{
if(mid[i].length()>maxx)
{
maxx=mid[i].length();
ans=mid[i];
}
}
string fin="";
for(i=0;i<v.size();i+=2)
{
fin+=v[i];
}
fin+=ans;
for(i=v.size()-1;i>0;i-=2)
{
fin+=v[i];
}
cout<<fin.length()<<endl;
cout<<fin<<endl;
return 0;
}

?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
?
?
?