Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int,int>
- using namespace std;
- using ll = long long;
- using ld = long double;
- void cv(vector <int> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvs(vector <string> v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- bool les(string a, string b){
- //cout<<"a b = "<<a<<" "<<b<<"\n";
- bool r = 0;
- if (a < b || a == b && a.size() < b.size()){
- return 1;
- }
- else if (a == b) return 0;
- else {
- int ai=a.size()-1, bi=b.size()-1;
- while (ai >= 0 && bi >= 0){//cout<<"GO\n";
- a += a[ai];
- b += b[bi];
- //cout<<"ai bi = "<<ai<<' '<<bi<<"\n";
- //cout<<"a b = "<<a<<' '<<b<<"\n";
- if (a < b){//cout<<"a < b\n";
- r = 1;
- break;
- }
- else if (b > a){//cout<<"b >= a\n";
- r = 0;
- break;
- }
- else{//cout<<"NEXT\n";
- ai--;
- bi--;
- //cout<<"ai bi = "<<ai<<' '<<bi<<"\n";
- if (ai < 0 || bi < 0) break;
- }
- }
- }
- //cout<<"DONE\n";
- return r;
- }
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- int t=1,n=1e5;
- //cin>>t;
- char l='x';
- for (int i=0;i<t;++i){
- //cin>>n;
- string s="";
- string mn = "";
- for (int j = 0;j<(n+1)/2;++j){
- mn += 'z';
- }
- for (int j=0;j<n;++j){
- //cin>>l;
- //cout<<"J = "<<j<<"\n";
- s += l;
- if ( les(s, mn) ){
- mn = s;
- //cout<<"mn = "<<mn<<"\n";
- }
- }
- for (int i = mn.size()-1; i >= 0;--i){
- //cout<<"i = "<<i<<"\n";
- mn += mn[i];
- }
- cout<<mn<<"\n";
- }
- }
- /*
- 10
- zdbaaaaabbbde
- zdbaabdz
- */
Add Comment
Please, Sign In to add comment