Submission #3004844
Source Code Expand
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n) for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
/*
8/13/2018
16:10-16:15 analysis
16:35 RE
*/
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
//const int MAX_N=1e5+1;
//int N;
string S;
//LL A[MAX_N];
int solve() {
int N=SZ(S);
vector<pair<char,int>> X={{'#',-1}};
string t; REP(i,N)if(S[i]!='x') {
t+=S[i];
X.emplace_back(S[i],i);
}
X.emplace_back('#',N);
string tt=t; reverse(tt.begin(),tt.end());
if(tt!=t) return -1;
int M=SZ(X);
int l=M/2,r=M%2==0?l+1:l;
--l,++r;
int res=0;
while(l>=0) {
// assert(X[l].first==X[r].first);
// dump4(X[l].first,X[l].second,X[r].first,X[r].second);
int d1=X[l+1].second-X[l].second,d2=X[r].second-X[r-1].second;
res+=max(d1,d2)-min(d1,d2);
// dump3(d1,d2,max(d1,d2)-min(d1,d2));
--l,++r;
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>S;
cout<<solve()<<endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
C - Inserting 'x' |
User |
kumalimak |
Language |
C++14 (Clang 3.8.0) |
Score |
0 |
Code Size |
2654 Byte |
Status |
WA |
Exec Time |
7 ms |
Memory |
1592 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 400 |
Status |
|
|
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 |
AC |
1 ms |
256 KB |
0_01.txt |
AC |
1 ms |
256 KB |
0_02.txt |
AC |
1 ms |
256 KB |
0_03.txt |
AC |
1 ms |
256 KB |
1_00.txt |
AC |
1 ms |
256 KB |
1_01.txt |
WA |
1 ms |
256 KB |
1_02.txt |
WA |
1 ms |
256 KB |
1_03.txt |
AC |
1 ms |
256 KB |
1_04.txt |
AC |
1 ms |
256 KB |
1_05.txt |
WA |
1 ms |
256 KB |
1_06.txt |
AC |
7 ms |
1592 KB |
1_07.txt |
WA |
6 ms |
512 KB |
1_08.txt |
WA |
7 ms |
1592 KB |
1_09.txt |
WA |
6 ms |
512 KB |
1_10.txt |
AC |
6 ms |
512 KB |
1_11.txt |
AC |
6 ms |
512 KB |
1_12.txt |
AC |
7 ms |
1592 KB |
1_13.txt |
WA |
6 ms |
512 KB |
1_14.txt |
AC |
6 ms |
512 KB |
1_15.txt |
WA |
6 ms |
512 KB |
1_16.txt |
AC |
6 ms |
512 KB |
1_17.txt |
AC |
6 ms |
512 KB |
1_18.txt |
AC |
6 ms |
512 KB |
1_19.txt |
WA |
6 ms |
512 KB |
1_20.txt |
AC |
6 ms |
512 KB |
1_21.txt |
WA |
6 ms |
704 KB |
1_22.txt |
AC |
6 ms |
704 KB |
1_23.txt |
AC |
7 ms |
956 KB |
1_24.txt |
AC |
7 ms |
956 KB |
1_25.txt |
WA |
7 ms |
956 KB |
1_26.txt |
AC |
7 ms |
1020 KB |
1_27.txt |
AC |
7 ms |
1592 KB |
1_28.txt |
AC |
7 ms |
1592 KB |