Please sign in first.
Submission #1706479
Source Code Expand
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
#define MP make_pair
#define PB push_back
#define FF first
#define SS second
#define FORN(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }
#define MOD 1000000007
#define INF 2000000000
int GLL(LL& x) {
return scanf("%lld", &x);
}
int GI(int& x) {
return scanf("%d", &x);
}
string s;
vector<pair<char, int>> fwd, bwd;
int main() {
cin >> s;
int n = s.size();
FORN(i, n) bwd.PB(MP(s[i], i));
fwd = bwd;
reverse(fwd.begin(), fwd.end());
int res = 0;
while (!fwd.empty() && !bwd.empty() && fwd.back().SS < bwd.back().SS) {
if (fwd.back().FF == bwd.back().FF) {
fwd.pop_back();
bwd.pop_back();
}
else if (fwd.back().FF == 'x') {
fwd.pop_back();
res++;
}
else if (bwd.back().FF == 'x') {
bwd.pop_back();
res++;
}
else {
printf("-1\n");
return 0;
}
}
printf("%d\n", res);
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Inserting 'x' |
| User | chenmark |
| Language | C++14 (GCC 5.4.1) |
| Score | 400 |
| Code Size | 1660 Byte |
| Status | AC |
| Exec Time | 7 ms |
| Memory | 2164 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 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 KiB |
| 0_01.txt | AC | 1 ms | 256 KiB |
| 0_02.txt | AC | 1 ms | 256 KiB |
| 0_03.txt | AC | 1 ms | 256 KiB |
| 1_00.txt | AC | 1 ms | 256 KiB |
| 1_01.txt | AC | 1 ms | 256 KiB |
| 1_02.txt | AC | 1 ms | 256 KiB |
| 1_03.txt | AC | 1 ms | 256 KiB |
| 1_04.txt | AC | 1 ms | 256 KiB |
| 1_05.txt | AC | 1 ms | 256 KiB |
| 1_06.txt | AC | 7 ms | 2036 KiB |
| 1_07.txt | AC | 7 ms | 2164 KiB |
| 1_08.txt | AC | 7 ms | 2164 KiB |
| 1_09.txt | AC | 7 ms | 2036 KiB |
| 1_10.txt | AC | 7 ms | 2036 KiB |
| 1_11.txt | AC | 7 ms | 2164 KiB |
| 1_12.txt | AC | 7 ms | 2164 KiB |
| 1_13.txt | AC | 6 ms | 2036 KiB |
| 1_14.txt | AC | 7 ms | 2036 KiB |
| 1_15.txt | AC | 7 ms | 2036 KiB |
| 1_16.txt | AC | 7 ms | 2036 KiB |
| 1_17.txt | AC | 7 ms | 2036 KiB |
| 1_18.txt | AC | 6 ms | 2036 KiB |
| 1_19.txt | AC | 7 ms | 2036 KiB |
| 1_20.txt | AC | 6 ms | 2036 KiB |
| 1_21.txt | AC | 7 ms | 2036 KiB |
| 1_22.txt | AC | 7 ms | 2036 KiB |
| 1_23.txt | AC | 7 ms | 2036 KiB |
| 1_24.txt | AC | 7 ms | 2036 KiB |
| 1_25.txt | AC | 7 ms | 2036 KiB |
| 1_26.txt | AC | 6 ms | 2036 KiB |
| 1_27.txt | AC | 6 ms | 2036 KiB |
| 1_28.txt | AC | 6 ms | 2036 KiB |