Submission #73704681
Source Code Expand
#include<bits/stdc++.h>
#include<atcoder/all>
#define rep(i,a,b) for(int i=a;i<(int)b;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull= unsigned long long;
using pii= pair<int,int>;
using pll= pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using atcoder::dsu;
using atcoder::segtree;//set,prod,get,all_prod
using atcoder::fenwick_tree;
using atcoder::modint998244353;
template<class T> bool chmax(T& a,const T& b)
{
if(a<b){
a=b;
return true;
}else{
return false;
}
}
template<class T> bool chmin(T& a,const T& b)
{
if(a>b){
a=b;
return true;
}else{
return false;
}
}
const int INF = 1e9;
const long long INFLL = (long long)1e18;
const double PI = acos(-1);
//cout << fixed << setprecision(15) << ans << '\n';
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
string s,t;cin>>s>>t;
if(s==t)
{
cout<<0<<"\n";
return 0;
}
bool c=false;
vector<char> woas,woat;
rep(i,0,s.size())
{
if(s[i]!='A')woas.push_back(s[i]-'A');
}
rep(i,0,t.size())
{
if(t[i]!='A')woat.push_back(t[i]-'A');
}
if(woas.size()!=woat.size())c=true;
else{
rep(i,0,woas.size())
{
if(woas[i]!=woat[i])
{
c=true;break;
}
}
}
if(c)
{
cout<<-1<<"\n";
return 0;
}
vl cnts(woas.size()+1),cntt(woas.size()+1);
ll tmp=0,pos=0;
rep(i,0,s.size())
{
if(s[i]=='A')
{
tmp++;
if(i!=(int)s.size()-1)continue;
else cnts[pos]=tmp;
}
else{
cnts[pos++]=tmp;
tmp=0;
}
}
tmp=0;pos=0;
rep(i,0,t.size())
{
if(t[i]=='A')
{
tmp++;
if(i!=(int)t.size()-1)continue;
else cntt[pos]=tmp;
}
else{
cntt[pos++]=tmp;
tmp=0;
}
}
ll ans=0;
rep(i,0,cntt.size())ans+=abs(cntt[i]-cnts[i]);
cout<<ans<<"\n";
return 0;
}
Submission Info
| Submission Time |
|
| Task |
C - Insert and Erase A |
| User |
maou1 |
| Language |
C++23 (Clang 21.1.0) |
| Score |
300 |
| Code Size |
2009 Byte |
| Status |
AC |
| Exec Time |
17 ms |
| Memory |
8256 KiB |
Compile Error
./Main.cpp:37:11: warning: unused variable 'INF' [-Wunused-const-variable]
37 | const int INF = 1e9;
| ^~~
./Main.cpp:38:17: warning: unused variable 'INFLL' [-Wunused-const-variable]
38 | const long long INFLL = (long long)1e18;
| ^~~~~
2 warnings generated.
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 |
2 ms |
2988 KiB |
| 00_sample_01.txt |
AC |
1 ms |
2964 KiB |
| 00_sample_02.txt |
AC |
1 ms |
2952 KiB |
| 00_sample_03.txt |
AC |
1 ms |
2756 KiB |
| 01_random_00.txt |
AC |
4 ms |
3252 KiB |
| 01_random_01.txt |
AC |
6 ms |
3580 KiB |
| 01_random_02.txt |
AC |
13 ms |
4444 KiB |
| 02_random2_00.txt |
AC |
8 ms |
3452 KiB |
| 02_random2_01.txt |
AC |
14 ms |
3776 KiB |
| 02_random2_02.txt |
AC |
16 ms |
8256 KiB |
| 02_random2_03.txt |
AC |
17 ms |
7780 KiB |
| 02_random2_04.txt |
AC |
13 ms |
6416 KiB |
| 02_random2_05.txt |
AC |
10 ms |
4344 KiB |
| 02_random2_06.txt |
AC |
14 ms |
7268 KiB |
| 02_random2_07.txt |
AC |
8 ms |
3856 KiB |
| 02_random2_08.txt |
AC |
14 ms |
4672 KiB |
| 02_random2_09.txt |
AC |
16 ms |
5472 KiB |
| 02_random2_10.txt |
AC |
13 ms |
7176 KiB |
| 02_random2_11.txt |
AC |
15 ms |
8168 KiB |
| 03_random3_00.txt |
AC |
13 ms |
4300 KiB |
| 03_random3_01.txt |
AC |
10 ms |
3656 KiB |
| 03_random3_02.txt |
AC |
11 ms |
3892 KiB |
| 03_random3_03.txt |
AC |
13 ms |
3792 KiB |
| 04_handmade_00.txt |
AC |
1 ms |
2988 KiB |
| 04_handmade_01.txt |
AC |
1 ms |
3036 KiB |
| 04_handmade_02.txt |
AC |
1 ms |
2892 KiB |
| 04_handmade_03.txt |
AC |
1 ms |
3000 KiB |
| 04_handmade_04.txt |
AC |
11 ms |
3636 KiB |
| 04_handmade_05.txt |
AC |
12 ms |
4040 KiB |
| 04_handmade_06.txt |
AC |
12 ms |
4116 KiB |
| 04_handmade_07.txt |
AC |
12 ms |
3712 KiB |
| 04_handmade_08.txt |
AC |
7 ms |
3216 KiB |
| 04_handmade_09.txt |
AC |
7 ms |
3424 KiB |