QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#679972#9430. Left Shifting 2HTensor#WA 2ms3620kbC++231.6kb2024-10-26 19:25:532024-10-26 19:25:54

Judging History

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

  • [2024-10-26 19:25:54]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3620kb
  • [2024-10-26 19:25:53]
  • 提交

answer

#include <bits/stdc++.h>
#define dd(x) cout << #x << "\n"
#define d(x) cout << #x  << ": " << x << "\n"
#define SZ(x) ((int)(x).size())
using namespace std;
#define int long long
using pii = pair<int, int>;
using vpii = vector<pii>;
using vi = vector<int>;
using vii = vector<vector<int>>;
using a3 = array<int, 3>;
using ll = long long;
const int inf = 0x3f3f3f3f3f3f3f3fLL;

#define MULTI_TEST

void solve() {
    string str; cin >> str; int n = SZ(str); str = " " + str;

    int st = 1, ed = n;
    vector<int> Q;
    if(str[1] == str[n]) {
        char xx = str[1];
        
        while(str[st] == xx) {
            ++st;
        }

        while(str[ed] == xx) {
            --ed;
        }

        int len = st - 1 + n - ed;
        int tt = min(len, n) - 1;
        Q.push_back(tt);

        if(tt == n - 1) {
            cout << (tt + 1) / 2 << "\n";
            return ;
        }
    }



    int cnt = 0;
    for(int i = st; i <= ed; i++) {
        if(str[i] == str[i - 1]) {
            cnt++;
        } else {
            if(cnt) {
                Q.push_back(cnt);
            }
        }
    }

    int ans = 0, mx = 0; 
    for(auto v : Q) {
        ans += (v + 1) / 2;
        mx = max(mx, (v + 1) / 2 - v / 2);
    }
    cout << ans - mx << "\n";
}

signed main() {
    ios::sync_with_stdio(false); cin.tie(0);
#ifdef MULTI_TEST
    int T; cin >> T;
#else
    int T = 1;
#endif
    while(T--) solve();
    return 0;
}

/*
3
abccbbbbd
abcde
x


1  
xxabcdxx

1
xxabcdxx


4
xxxax
xxxxa
xaxxx
xxaxx

2
xxxaxx
xxaxxx

2
xx
xxx

1
aaaaa

1
aaaaaa
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
abccbbbbd
abcde
x

output:

2
0
0

result:

ok 3 lines

Test #2:

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

input:

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

output:

26
0
18
52
4
1
21
63
17
0
28
19
5
17
62
94
2
20
87
108
8
2
127
78
4
10
36
45
0
80
2
0
0
0
64
0
17
103
101
128
5
21
0
138
94
11
86
32
0
46
145
1
17
192
62
25
8
32
0
1
114
7
63
44
33
2
90
54
176
1
91
41
47
0
15
6
71
48
19
124
68
100
126
0
108
0
154
1
0
80
64
19
80
0
55
141
15
73
57
41
106
105
43
33
10...

result:

wrong answer 1st lines differ - expected: '1', found: '26'