QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#697769 | #9430. Left Shifting 2 | Spinoza | WA | 2ms | 3632kb | C++20 | 1.3kb | 2024-11-01 15:41:48 | 2024-11-01 15:41:48 |
Judging History
answer
#include<bits/stdc++.h>
const int P = 998244353;
typedef long long ll;
#define rep(i,x,y) for (int i=(x);i<=(y);++i)
using namespace std;
void solve() {
string s;
cin >> s;
int n = s.length();
bool op = false;
int l = 0;
int r = n - 1;
while (l < n && s[l] == s[0]) l++;
while (r >= 0 && s[r] == s[n - 1]) r--;
l--;
r++;
int ans = 0;
if (s[0] == s[n - 1] && l < r) {
int lenl = l + 1;
int lenr = n - r;
int cnt1 = (lenl + lenr) / 2;
int cnt2 = lenl / 2 + lenr / 2;
ans = cnt2;
op = true;
} else if (s[0] == s[n - 1] && l >= r) {
cout << n / 2 << '\n';
return;
}
if (s[0] == s[n - 1]) {
rep(i, l + 1, r - 1) {
int pos = i;
while (pos < n && s[pos] == s[i]) pos++;
int cnt = pos - i;
ans += cnt / 2;
i = pos - 1;
}
} else {
rep(i, 0, n - 1) {
int pos = i;
while (pos < n && s[pos] == s[i]) pos++;
int cnt = pos - i;
if (cnt % 2 == 0 && (cnt >= 2)) {
if (!op) {
ans += (cnt - 2) / 2;
op = true;
} else {
ans += cnt / 2;
}
} else if (cnt % 2) {
ans += cnt / 2;
}
i = pos - 1;
}
}
cout << ans << '\n';
return;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t = 1;
cin >> t;
while (t--) solve();
return 0;
}
/*
3
abccbbbbd
abcde
x
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3632kb
input:
3 abccbbbbd abcde x
output:
2 0 0
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 3580kb
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 1 0 6 1 2 0 1 0 0 4 1 2 4 3 1 3 2 3 1 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 591st lines differ - expected: '2', found: '3'