Submission #7357088


Source Code Expand

Copy
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

signed main() {
  INIT;
  VAR(string, s);
  vector<int> cnt(26,0);
  REP(i,s.size()){
    cnt[s[i]-'a']++;
  }

  int center = 0, num = 0;
  REP(i,cnt.size()){
    if (i == 'x'-'a') continue;
    if (cnt[i]%2==1) {
      ++center;
      num = i;
    }
  }

  if (center > 1) {
    OUT(-1)BR;
    return 0;
  }

  int ans = 0, lb=0, ub=s.size()-1;
  REP(i,s.size()) {
    if (lb >= ub){
      break;
    }
    if (s[lb] == s[ub]) {
      ++lb;
      --ub;
      continue;
    }
    ++ans;
    if (s[lb] == 'x') {
      ++lb;
    } else if (s[ub] == 'x') {
      --ub;
    } else {
      OUT(-1)BR;
      return 0;
    }
  }
  OUT(ans)BR;
  
  return 0;
}

Submission Info

Submission Time
Task C - Inserting 'x'
User task4233
Language C++14 (GCC 5.4.1)
Score 400
Code Size 2150 Byte
Status
Exec Time 2 ms
Memory 512 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
× 4
× 33
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt
Case Name Status Exec Time Memory
0_00.txt 1 ms 256 KB
0_01.txt 1 ms 256 KB
0_02.txt 1 ms 256 KB
0_03.txt 1 ms 256 KB
1_00.txt 1 ms 256 KB
1_01.txt 1 ms 256 KB
1_02.txt 1 ms 256 KB
1_03.txt 1 ms 256 KB
1_04.txt 1 ms 256 KB
1_05.txt 1 ms 256 KB
1_06.txt 2 ms 512 KB
1_07.txt 2 ms 512 KB
1_08.txt 2 ms 512 KB
1_09.txt 2 ms 512 KB
1_10.txt 2 ms 512 KB
1_11.txt 2 ms 512 KB
1_12.txt 2 ms 512 KB
1_13.txt 2 ms 512 KB
1_14.txt 2 ms 512 KB
1_15.txt 2 ms 512 KB
1_16.txt 2 ms 512 KB
1_17.txt 2 ms 512 KB
1_18.txt 2 ms 512 KB
1_19.txt 2 ms 512 KB
1_20.txt 2 ms 512 KB
1_21.txt 2 ms 512 KB
1_22.txt 2 ms 512 KB
1_23.txt 2 ms 512 KB
1_24.txt 2 ms 512 KB
1_25.txt 2 ms 512 KB
1_26.txt 1 ms 384 KB
1_27.txt 2 ms 512 KB
1_28.txt 2 ms 512 KB