Submission #73684065
Source Code Expand
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
struct A_Distribution {
long long pre;
vector<long long> between;
long long suf;
};
vector<char> get_core(const string &s) {
vector<char> core;
for (char c : s) {
if (c != 'A') {
core.push_back(c);
}
}
return core;
}
A_Distribution get_a_dist(const string &s, const vector<char> &core) {
A_Distribution dist;
dist.pre = 0;
dist.between.clear();
dist.suf = 0;
int n = s.size();
if (core.empty()) {
dist.pre = n;
return dist;
}
int ptr = 0;
while (ptr < n && s[ptr] == 'A') {
dist.pre++;
ptr++;
}
ptr++;
for (int i = 1; i < core.size(); ++i) {
long long cnt = 0;
while (ptr < n && s[ptr] == 'A') {
cnt++;
ptr++;
}
dist.between.push_back(cnt);
ptr++;
}
while (ptr < n) {
if (s[ptr] == 'A') {
dist.suf++;
}
ptr++;
}
return dist;
}
int main() {
string S, T;
cin >> S >> T;
vector<char> core_S = get_core(S);
vector<char> core_T = get_core(T);
if (core_S != core_T) {
cout << -1 << endl;
return 0;
}
A_Distribution dist_S = get_a_dist(S, core_S);
A_Distribution dist_T = get_a_dist(T, core_T);
long long ans = abs(dist_S.pre - dist_T.pre);
for (int i = 0; i < dist_S.between.size(); ++i) {
ans += abs(dist_S.between[i] - dist_T.between[i]);
}
ans += abs(dist_S.suf - dist_T.suf);
cout << ans;
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Insert and Erase A |
| User | xuhanjin |
| Language | C++23 (GCC 15.2.0) |
| Score | 300 |
| Code Size | 1696 Byte |
| Status | AC |
| Exec Time | 15 ms |
| Memory | 13192 KiB |
Compile Error
./Main.cpp: In function 'A_Distribution get_a_dist(const std::string&, const std::vector<char>&)':
./Main.cpp:36:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for (int i = 1; i < core.size(); ++i) {
| ~~^~~~~~~~~~~~~
./Main.cpp: In function 'int main()':
./Main.cpp:66:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for (int i = 0; i < dist_S.between.size(); ++i) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 300 / 300 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 02_random2_06.txt, 02_random2_07.txt, 02_random2_08.txt, 02_random2_09.txt, 02_random2_10.txt, 02_random2_11.txt, 03_random3_00.txt, 03_random3_01.txt, 03_random3_02.txt, 03_random3_03.txt, 04_handmade_00.txt, 04_handmade_01.txt, 04_handmade_02.txt, 04_handmade_03.txt, 04_handmade_04.txt, 04_handmade_05.txt, 04_handmade_06.txt, 04_handmade_07.txt, 04_handmade_08.txt, 04_handmade_09.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 1 ms | 3592 KiB |
| 00_sample_01.txt | AC | 1 ms | 3424 KiB |
| 00_sample_02.txt | AC | 1 ms | 3580 KiB |
| 00_sample_03.txt | AC | 1 ms | 3536 KiB |
| 01_random_00.txt | AC | 3 ms | 3824 KiB |
| 01_random_01.txt | AC | 4 ms | 3904 KiB |
| 01_random_02.txt | AC | 9 ms | 5044 KiB |
| 02_random2_00.txt | AC | 10 ms | 8648 KiB |
| 02_random2_01.txt | AC | 10 ms | 4560 KiB |
| 02_random2_02.txt | AC | 14 ms | 9500 KiB |
| 02_random2_03.txt | AC | 14 ms | 9104 KiB |
| 02_random2_04.txt | AC | 12 ms | 8380 KiB |
| 02_random2_05.txt | AC | 7 ms | 5132 KiB |
| 02_random2_06.txt | AC | 12 ms | 9732 KiB |
| 02_random2_07.txt | AC | 6 ms | 4892 KiB |
| 02_random2_08.txt | AC | 11 ms | 6248 KiB |
| 02_random2_09.txt | AC | 13 ms | 7040 KiB |
| 02_random2_10.txt | AC | 11 ms | 9056 KiB |
| 02_random2_11.txt | AC | 13 ms | 9540 KiB |
| 03_random3_00.txt | AC | 9 ms | 5000 KiB |
| 03_random3_01.txt | AC | 8 ms | 4260 KiB |
| 03_random3_02.txt | AC | 8 ms | 4524 KiB |
| 03_random3_03.txt | AC | 9 ms | 4372 KiB |
| 04_handmade_00.txt | AC | 1 ms | 3424 KiB |
| 04_handmade_01.txt | AC | 1 ms | 3644 KiB |
| 04_handmade_02.txt | AC | 1 ms | 3576 KiB |
| 04_handmade_03.txt | AC | 1 ms | 3624 KiB |
| 04_handmade_04.txt | AC | 15 ms | 13192 KiB |
| 04_handmade_05.txt | AC | 9 ms | 4692 KiB |
| 04_handmade_06.txt | AC | 9 ms | 4688 KiB |
| 04_handmade_07.txt | AC | 8 ms | 4392 KiB |
| 04_handmade_08.txt | AC | 5 ms | 3928 KiB |
| 04_handmade_09.txt | AC | 5 ms | 4100 KiB |