QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#691990 | #9430. Left Shifting 2 | Z-wzy | WA | 2ms | 3556kb | C++20 | 934b | 2024-10-31 13:34:56 | 2024-10-31 13:34:59 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define P pair<int,int>
const int mod = 1e9 + 7, inf = 1e17;
void run(){
string s;
cin >> s;
int n = s.size();
int ans = 0;
vector<int> g;
int ok = 0;
for(int i=0;i<n;i++){
int res = 1;
while(i < n - 1 && s[i] == s[i + 1]){
i ++;
res ++;
}
g.push_back(res);
ans += res / 2;
ok |= (res % 2 == 0);
}
if(g.size() == 1){
cout << ans << '\n';
return;
}
if(s[0] == s[n - 1]){
int x = *g.begin();
int y = g.back();
cout << ans - (x % 2 == 0 && y % 2 == 0) << '\n';
}
else{
cout << ans - ok << '\n';
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T = 1;
cin >> T;
while(T --) run(); return 0;
}
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: 3556kb
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'