QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#630081#9430. Left Shifting 2qwqpmp#WA 3ms3632kbC++141.4kb2024-10-11 16:24:312024-10-11 16:24:33

Judging History

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

  • [2024-10-11 16:24:33]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3632kb
  • [2024-10-11 16:24:31]
  • 提交

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; ll ans = 0;
	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'), ans += f(j - i);	
		i = j - 1;
	}
	if (SZ(l) == 1) {
		cout << ans << endl;
		return;
	}
	// cerr << ans << endl;
	ll ret = ans;
	for (int i = 0; i < SZ(l); i++) {
		int id = (i + SZ(l) - 1) % SZ(l);
		if (l[id].se == l[i].se) {
			if (l[id].fi % 2 == 0 and l[i].fi % 2 == 0) {
				ret = min(ret, ans - 1);
			}
		} else {
			if (l[id].fi % 2 == 0) {
				ret = min(ret, ans - 1);
			}
		}
	}
	cout << ret << endl;
}

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

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
abccbbbbd
abcde
x

output:

2
0
0

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 3632kb

input:

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

output:

1
0
0
0
0
0
1
4
0
0
1
1
0
1
1
3
0
0
5
6
0
0
5
2
0
1
3
1
0
3
0
1
0
1
1
0
1
4
1
3
1
0
1
5
3
0
3
0
0
1
7
1
0
6
1
2
0
1
0
0
4
1
2
4
3
1
3
2
3
1
2
0
0
0
2
0
2
2
0
4
0
5
5
0
3
0
4
0
0
2
1
0
2
0
1
6
1
2
0
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
2
3
3
1
2
0
1
1
4
2
1
3
0
1
1
2
0
1
2
0
4
0
1
1
...

result:

wrong answer 13th lines differ - expected: '1', found: '0'