1867B - XOR Palindromes - CodeForces Solution


constructive algorithms strings

Please click on ads to support us..

C++ Code:

/* ۝ وَأَنْ لَيْسَ لِلإِنسَانِ إِلَّا مَا سَعَى ۝ وَأَنَّ سَعْيَهُ سَوْفَ يُرَى ۝ ثُمَّ يُجْزَاهُ الْجَزَاءَ الأَوْفَى ۝ */

#include <iostream>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
using namespace __gnu_pbds;
using namespace std;
template<typename T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll INF=1e18;
const int N =1e6+5;
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};



int main()
{
IO;
int t;
cin>>t;
while(t--){
int n;
string s;
ll com=0;
cin>>n;
cin>>s;
vector<char>arr(n+1,'0');
for(int i=0;i<n/2;i++){
  if(s[i]!=s[n-i-1])com++;
}
for(int i=com;i<=n;i+=(1+(n%2==0))){

if(n-i>=i)arr[i]='1',arr[n-i]='1';

}
for(int i=0;i<=n;i++)
cout<<arr[i];
cout<<'\n';

}



}


Comments

Submit
0 Comments
More Questions

124A - The number of positions
1041A - Heist
901A - Hashing Trees
1283A - Minutes Before the New Year
1654D - Potion Brewing Class
1107B - Digital root
25A - IQ test
785A - Anton and Polyhedrons
1542B - Plus and Multiply
306A - Candies
1651C - Fault-tolerant Network
870A - Search for Pretty Integers
1174A - Ehab Fails to Be Thanos
1169A - Circle Metro
780C - Andryusha and Colored Balloons
1153A - Serval and Bus
1487C - Minimum Ties
1136A - Nastya Is Reading a Book
1353B - Two Arrays And Swaps
1490E - Accidental Victory
1335A - Candies and Two Sisters
96B - Lucky Numbers (easy)
1151B - Dima and a Bad XOR
1435B - A New Technique
1633A - Div 7
268A - Games
1062B - Math
1294C - Product of Three Numbers
749A - Bachgold Problem
1486B - Eastern Exhibition