rt,这是我在赛时拿了 100 pts 的代码:
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
#define N 1000010
int n, len = 0;
string s[N];
int main(){
ios::sync_with_stdio(false);
cin >> n;
int _max = 0, max_cnt = 0, k = 0;
for(int i = 1; i <= n; ++i){
cin >> s[i];
len += s[i].size();
int cnt = 1;
for(int j = 1; j < s[i].size(); ++j) if(s[i][j] != s[i][j - 1]) ++cnt;
if(cnt == _max && s[i] != s[k]) ++max_cnt;
else if(_max < cnt){
_max = cnt;
max_cnt = 0;
k = i;
}
}
if(max_cnt) ++_max;
cout << len - _max << endl;
return 0;
}
然而这份数据可以叉掉上面的代码:
2
1110
1000
容易发现,方案 1,1,1,2,1,2,2,2 的答案为 6,然而跑出来的结果却是 5。请求添加 hack 数据。