QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#743461 | #5422. Perfect Palindrome | Mocic1 | WA | 20ms | 4176kb | C++14 | 1.1kb | 2024-11-13 19:17:03 | 2024-11-13 19:17:04 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define int long long
#define pb push_back
#define ff first
#define ss second
typedef pair<int, int> PII;
const int N = 300007;
const int inf = 1e18;
const int mod = 1e9+7;
mt19937_64 rng(time(0));
void solve() {
string a;
cin>>a;
int len=a.length();
map<char,int>mp;
for(auto i:a){
mp[i]++;
}
vector<int>v;
for(auto i:mp){
v.pb(i.ss);
}
sort(v.begin(),v.end());
if(len&1){
cout<<len-v[v.size()-1]<<'\n';
}
else{
if(len!=4){
cout<<len-v[v.size()-1]<<'\n';
}
else{
if(a[0]==a[1]&&a[2]==a[3]){
cout<<0<<'\n';
}
else if(mp.size()==4)cout<<3<<'\n';
else{
cout<<min((a[0]!=a[1])+(a[2]!=a[3]),(a[0]!=a[3])+(a[1]!=a[2]))<<'\n';
}
}
}
}
signed main() {
ios;
int _ = 1;
cin >> _;
while (_--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3608kb
input:
2 abcb xxx
output:
2 0
result:
ok 2 number(s): "2 0"
Test #2:
score: -100
Wrong Answer
time: 20ms
memory: 4176kb
input:
11107 lfpbavjsm pdtlkfwn fmb hptdswsoul bhyjhp pscfliuqn nej nxolzbd z clzb zqomviosz u ek vco oymonrq rjd ktsqti mdcvserv x birnpfu gsgk ftchwlm bzqgar ovj nsgiegk dbolme nvr rpsc fprodu eqtidwto j qty o jknssmabwl qjfv wrd aa ejsf i npmmhkef dzvyon p zww dp ru qmwm sc wnnjyoepxo hc opvfepiko inuxx...
output:
8 7 2 8 4 8 2 6 0 3 7 0 1 2 5 2 4 6 0 6 2 6 5 2 5 5 2 3 5 6 0 2 0 8 3 2 0 3 0 6 5 0 1 1 1 2 1 8 1 7 5 3 4 4 1 8 5 5 8 8 6 3 0 2 3 2 1 5 0 0 9 3 3 4 8 4 0 4 2 6 6 0 8 7 4 3 9 3 4 2 5 8 8 8 6 1 4 4 2 7 1 8 6 4 4 8 7 8 4 9 3 8 0 7 7 2 6 0 0 5 4 0 7 5 4 1 1 6 7 5 2 4 4 7 3 3 2 5 4 8 5 0 3 5 1 2 3 0 4 7 ...
result:
wrong answer 101st numbers differ - expected: '2', found: '1'