QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#642376 | #9430. Left Shifting 2 | Andeviking | WA | 3ms | 3828kb | C++20 | 1.5kb | 2024-10-15 13:39:42 | 2024-10-15 13:39:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define range(x) (x).begin(), (x).end()
const int dir[][2] = {1, 0, -1, 0, 0, 1, 0, -1};
int get(int x)
{
return x / 2;
}
void solve()
{
deque<pair<char, int>> dq;
string s;
cin >> s;
int n = s.size();
s += s;
int l = 0, r = n - 1;
char last = 0;
int cnt = 0;
int ans = 0;
for (int i = l; i < r; ++i) {
if (!last) {
last = s[i];
cnt = 1;
}
else if (s[i] == last)
cnt++;
else {
dq.emplace_back(last, cnt);
ans += get(cnt);
cnt = 1;
last = s[i];
}
}
dq.emplace_back(last, cnt);
ans += get(cnt);
cnt = 0;
int mi = ans;
l++;
while (l < n) {
char st = dq.front().first;
ans -= get(dq.front().second);
dq.front().second--;
if (!dq.front().second)
dq.pop_front();
else
ans += get(dq.front().second);
char ed = dq.back().first;
if (ed == st) {
ans -= get(dq.back().second);
dq.back().second++;
ans += get(dq.back().second);
}
else
dq.emplace_back(st, 1);
mi = min(mi, ans);
l++;
}
cout << mi << '\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3828kb
input:
3 abccbbbbd abcde x
output:
2 0 0
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 3ms
memory: 3560kb
input:
5000 lfpbavjsmppdppkfwnyfmbdhptdswsoulrbhyjh cfliuqnynejgnxolzbdoztclzbozqomvioszk eiivcoqoymonrqgrjdtkts mdcvservaxcbioopfungsgkiftchwlmtbzqgaraovjknsgiegkvdbolmeunvrxrpscnf ujeqtidwtoikkqtygo llma qjfvgwrdhaazejsfgilnpmmhkefndzvyon kzwwpdpbrudqmwmjscllnnjyoepxophcoopvfepikouinuxx vftculoorxskpkxoz...
output:
1 0 0 0 0 0 1 3 0 0 1 1 0 1 1 3 0 0 5 6 0 0 5 2 0 1 2 1 0 3 1 0 0 0 1 0 1 4 1 3 1 1 0 5 3 0 3 0 0 1 7 0 0 5 1 2 0 1 0 0 4 1 2 4 3 1 3 2 3 0 3 0 0 0 2 0 1 2 0 4 0 5 6 0 3 0 3 0 0 2 1 0 2 0 1 6 1 2 0 3 3 3 5 2 3 0 3 5 1 3 1 0 3 1 5 5 3 2 1 1 0 0 2 0 1 1 2 3 3 0 2 0 0 1 4 2 1 3 0 1 1 2 0 1 2 0 4 0 1 1 ...
result:
wrong answer 8th lines differ - expected: '4', found: '3'