QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#762878#9430. Left Shifting 2HaijieTanWA 3ms3656kbC++232.3kb2024-11-19 17:03:182024-11-19 17:03:21

Judging History

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

  • [2024-11-19 17:03:21]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3656kb
  • [2024-11-19 17:03:18]
  • 提交

answer

#include<iostream>
#include<vector>
#include<bitset>
#include<algorithm>
#include<cmath>
#include<queue>
#include<numeric>//iota -- iota(all(a), x) a从头到尾从x开始递增
#include<cstring>
#include<ctime>
#include<array>
#include<list>
#include<random>
#include<tuple>
#include<deque>
#include<map>
#include<stack>
#include<set>
using namespace std;
template <typename Dtype>
unsigned int __builtin_popcount(Dtype u)
{
	u = (u & 0x55555555) + ((u >> 1) & 0x55555555);
	u = (u & 0x33333333) + ((u >> 2) & 0x33333333);
	u = (u & 0x0F0F0F0F) + ((u >> 4) & 0x0F0F0F0F);
	u = (u & 0x00FF00FF) + ((u >> 8) & 0x00FF00FF);
	u = (u & 0x0000FFFF) + ((u >> 16) & 0x0000FFFF);
	return u;
}//wishchin!!!  
#define IOS ios::sync_with_stdio(false);cin.tie(0), cout.tie(0)
#define int long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define pf push_front
#define lowbit(x) (x & (-x))
const int xy[][2] = { 0,1, 0, -1, 1, 0, -1, 0 };
#define mem(a, x) memset(a, x, sizeof a)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef pair<char, char> PCC;
typedef pair<int, char> PIC;
typedef pair<char, int> PCI;
#define x first
#define y second
#define NO cout << "NO\n"
#define YES cout << "YES\n"
inline int read();
const int INF = 0x3f3f3f3f, N = 1e6 + 10, MOD = 1e9 + 7, M = 1e4 + 10, K = 131;
const double PI = acos(-1.0);
void solve() {
	string s; cin >> s;
	int n = s.size(), index = 0, sum = 0, cnt = 0;
	if (n == 1)return cout << "0\n", void();
	int t = 1;
	while (index < n) {
		t = 1;
		while (index < n - 1 && s[index] == s[index + 1])index++, t++;
		sum += t / 2;
		if (t % 2 == 0) {
			//cnt = max(cnt, t / 2 - 1);
			cnt = 1;
		}
		index++;
	}
	if (s[0] == s[n - 1]) {
		if (t % 2)cout << sum << endl;
		else cout << sum - cnt << endl;
	}
	else cout << sum - cnt << endl;
	//if (cnt)cnt -= s[0] == s[n - 1];
	//cout << sum - cnt  << endl;
}
signed main() {
	IOS;
	int _ = 1;
	cin >> _;
	while (_--)solve();
	return 0;
}
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch>'9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
	return x * f;
}
/*   /\_/\
*   (= ._.)
*   / >  \>
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
abccbbbbd
abcde
x

output:

2
0
0

result:

ok 3 lines

Test #2:

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

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'