ABC145 B - Echo

Calendar Clock iconCalendar Clock icon

atcoder

Table of contents

# Problem

https://atcoder.jp/contests/abc145/tasks/abc145_b

Given a string SS, report if SS is twice repetitions of a string or not.

# Explanation

If the length of SS is odd, report No.
Otherwise, split SS in the middle into S1S1 and S2S2.
If S1S1 equals to S2S2, report Yes.

# Time complexity

Half of the length of SS.

O(N/2)O(N / 2)

# Solution

// C++ 14
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <math.h>

#define ll long long
#define Int int
#define loop(x, start, end) for(Int x = start; x < end; x++)
#define loopdown(x, start, end) for(int x = start; x > end; x--)
#define rep(n) for(int x = 0; x < n; x++)
#define span(a,x,y) a.begin()+x,a.begin()+y
#define span_all(a) a.begin(),a.end()
#define len(x) (x.size())
#define last(x) (*(x.end()-1))

using namespace std;
Int N;
string S;

void input() {
  cin >> N >> S;
}

void solve() {
  if (N % 2 == 1) {
    cout << "No" << endl;
    return;
  }

  if (S.substr(0, N/2) == S.substr(N/2)) cout << "Yes" << endl;
  else cout << "No" << endl;
}

int main(void) {
  input();
  solve();
  return 0;
}

Remote freelancer. A web and mobile application enginner.
Traveling around the world based on East Asia.
I'm looking forward to your job offers from all over the world!

Offer jobs or contact me!

Comments