Submission #38197260


Source Code Expand

Copy
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
using ll=long long;
signed main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n,a,b;cin>>n>>a>>b;
string t;cin>>t;
ll ans=0x3f3f3f3f3f3f3f3f;
for(int i=0;i<n;++i){
string s=t.substr(i)+t.substr(0,i);
ll res=(ll)a*i;
for(int l=0,r=n-1;l<=r;++l,--r){
if(s[l]!=s[r])res+=b;
}
ans=min(ans,res);
}
cout<<ans;
return 0;
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
using ll=long long;

signed main() {
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n,a,b;cin>>n>>a>>b;
    string t;cin>>t;
    ll ans=0x3f3f3f3f3f3f3f3f;
    for(int i=0;i<n;++i){
        string s=t.substr(i)+t.substr(0,i);
        ll res=(ll)a*i;
        for(int l=0,r=n-1;l<=r;++l,--r){
            if(s[l]!=s[r])res+=b;
        }
        ans=min(ans,res);
    }
    cout<<ans;
	return 0;
}
// init?
// var->0?
// infinite dfs?
// out of bound?
// max_element / min_element?

Submission Info

Submission Time
Task C - Rotate and Palindrome
User wa_wa_vegetable
Language C++ (GCC 9.2.1)
Score 300
Code Size 601 Byte
Status AC
Exec Time 30 ms
Memory 3708 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 17
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt
All 00_sample_01.txt, 00_sample_02.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 5 ms 3648 KB
00_sample_02.txt AC 1 ms 3568 KB
01_test_01.txt AC 23 ms 3564 KB
01_test_02.txt AC 22 ms 3604 KB
01_test_03.txt AC 22 ms 3708 KB
01_test_04.txt AC 30 ms 3668 KB
01_test_05.txt AC 25 ms 3668 KB
01_test_06.txt AC 29 ms 3624 KB
01_test_07.txt AC 26 ms 3604 KB
01_test_08.txt AC 22 ms 3636 KB
01_test_09.txt AC 23 ms 3616 KB
01_test_10.txt AC 23 ms 3564 KB
01_test_11.txt AC 25 ms 3668 KB
01_test_12.txt AC 27 ms 3628 KB
01_test_13.txt AC 21 ms 3620 KB
01_test_14.txt AC 25 ms 3664 KB
01_test_15.txt AC 21 ms 3676 KB


2025-02-28 (Fri)
09:42:18 +00:00