QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#630166#9430. Left Shifting 2qwqpmp#WA 2ms3560kbC++141.3kb2024-10-11 16:51:172024-10-11 16:51:18

Judging History

你现在查看的是最新测评结果

  • [2024-10-11 16:51:18]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3560kb
  • [2024-10-11 16:51:17]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i = a; i < n; i++)
#define per(i,a,n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define endl '\n'
#define SZ(x) ((int)(x).size())
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }
const ll mod = 1000000007;
// head

typedef vector<pii> vp;
string s;

int f(int x) {
	if (x == 1) return 0;
	else if (x == 2) return 1;
	return (x / 2);
}

void solve() {
	cin >> s;
	vp l;
	for (int i = 0, j = 0; i < SZ(s); i++) {
		j = i;
		while (s[i] == s[j] and j < SZ(s)) j++;
		l.eb(j - i, s[i] - 'a');	
 		i = j - 1;
	}
	if (SZ(l) == 1) {
		cout << f(SZ(l)) << endl;
		return;
	}
	if (l.back().se == l[0].se) {
		l[0].fi += l.back().fi;
		l.pop_back();
	}
	ll ans = 0, ok = 0;
	for (auto x : l) {
		ans += f(x.fi);
		ok |= (x.fi % 2 == 0);
	}
	cout << ans - ok << endl;
}

int tc;
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);

	// freopen("qwq.in", "r", stdin);
	// freopen("qwq.out", "w", stdout);

	cin >> tc;
	while (tc -- ) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3544kb

input:

3
abccbbbbd
abcde
x

output:

2
0
0

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 3560kb

input:

5000
lfpbavjsmppdppkfwnyfmbdhptdswsoulrbhyjh
cfliuqnynejgnxolzbdoztclzbozqomvioszk
eiivcoqoymonrqgrjdtkts
mdcvservaxcbioopfungsgkiftchwlmtbzqgaraovjknsgiegkvdbolmeunvrxrpscnf
ujeqtidwtoikkqtygo
llma
qjfvgwrdhaazejsfgilnpmmhkefndzvyon
kzwwpdpbrudqmwmjscllnnjyoepxophcoopvfepikouinuxx
vftculoorxskpkxoz...

output:

1
0
0
0
0
0
1
4
0
0
1
1
1
1
1
3
1
0
5
6
0
0
5
2
0
1
3
2
0
3
0
1
0
1
1
0
1
4
1
3
1
0
1
5
3
0
3
0
0
1
8
0
0
6
1
2
0
1
0
0
4
1
2
4
3
1
3
2
3
0
2
1
0
0
2
0
2
2
0
4
0
5
5
0
3
0
4
1
0
2
1
0
2
0
1
6
1
2
1
3
3
3
5
2
3
0
3
5
1
3
0
0
3
0
4
5
3
2
1
1
0
0
2
0
1
1
3
3
3
1
2
0
1
1
4
3
1
3
1
1
1
2
0
1
2
0
4
0
1
1
...

result:

wrong answer 52nd lines differ - expected: '1', found: '0'