QOJ.ac
QOJ
ID | 提交记录ID | 题目 | Hacker | Owner | 结果 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|
#1148 | #713435 | #9565. Birthday Gift | ucup-team1196 | ucup-team1196 | Failed. | 2024-11-08 00:23:36 | 2024-11-08 00:23:36 |
详细
Extra Test:
Accepted
time: 1ms
memory: 3640kb
input:
50 110211020010110011100101101010000011022010111202011001001011102001101000011001211000221211110110000110021000110101120100110100011010011001110110011000101021122001001101101101101011010101110101100001111001011210211101201001200101010010011210001201111000000010000110101100120011001100001112121011100...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 17 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
result:
ok 50 numbers
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#713435 | #9565. Birthday Gift | ucup-team1196# | AC ✓ | 12ms | 8780kb | C++23 | 1019b | 2024-11-05 19:22:23 | 2024-11-09 01:53:38 |
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
string s;
cin>>s;
int n=s.size();
if(n==1){
cout<<1<<"\n";
return;
}
stack<int>st;
for(int i=0;i<n;++i){
int x=s[i]-'0';
if(!st.empty() && x!=2 && st.top()==x){
st.pop();
}
else st.push(x);
}
vector<int>a;
while(!st.empty()){
a.push_back(st.top());
st.pop();
}
int sz=a.size();
int r[3]={0,0,0};
int cur=0;
for(int i=1;i<sz;i+=2){
if(a[i]==2) continue;
a[i]^=1;
}
for(int i=0;i<sz;++i) r[a[i]]++;
int ma=max(r[0],r[1]),mi=min(r[0],r[1]);
if(mi+r[2]>=ma){
int ans=r[0]+r[1]+r[2];
cout<<(ans&1)<<"\n";
}
else cout<<ma-mi-r[2]<<"\n";
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int t = 1;
std::cin >> t;
while (t --) {
solve();
}
}