QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#739120 | #9565. Birthday Gift | ewe | WA | 0ms | 3776kb | C++14 | 2.1kb | 2024-11-12 20:55:33 | 2024-11-12 20:55:35 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define fopen \
freopen("E:/vscode/oi/in.txt", "r", stdin); \
freopen("E:/vscode/oi/out.txt", "w", stdout);
#define ios \
ios::sync_with_stdio(0); \
cin.tie(0);
#define i64 long long
#define ull unsigned i64
#define pii pair<int, int>
#define pdd pair<double, double>
#define ld long double
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)
#define lowbit(x) (x & -x)
#define de(x) cout << #x << " = " << x << '\n'
#define MAXP 20
const int N = 2e5 + 10, M = 1e2 + 10;
const double eps = 1e-12;
const double PI = acos(-1);
bool Mst;
char s[N];
int stk[N], top;
int c[2], col[N];
void solve()
{
cin >> s + 1;
top = c[0] = c[1] = 0;
int n = strlen(s + 1);
for (int i = 1; i <= n; i++)
{
if (s[i] != '2' && top && s[stk[top]] == s[i])
--top;
else
stk[++top] = i;
}
for (int i = 1; i <= top; i++)
s[i] = s[stk[i]];
n = top, s[n + 1] = 0;
int siz = 0;
for (int i = 1; i <= n; i++)
if (s[i] != '2')
{
col[i] = col[i - 1];
++c[col[i]];
}
else
{
int j = i;
while (s[j] == '2')
++j;
int len = j - i;
siz += len;
if (len & 1)
{
if (s[i - 1] == s[j])
col[j] = col[i - 1] ^ 1;
else
col[j] = col[i - 1];
}
else
{
if (s[i - 1] != s[j])
col[j] = col[i - 1] ^ 1;
else
col[j] = col[i - 1];
}
i = j - 1;
}
cout << max(0, abs(c[0] - c[1]) - siz) << '\n';
}
bool Med;
signed main()
{
ios;
// fopen;
cerr << (&Med - &Mst) / 1024 / 1024;
int t = 1;
srand(time(0));
cout << fixed << setprecision(12);
cin >> t;
for (int i = 1; i <= t; i++)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3776kb
input:
5 0110101 01020102 0000021111 1012121010 0100202010
output:
3 4 0 6 4
result:
wrong answer 5th numbers differ - expected: '0', found: '4'