QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#727137 | #9565. Birthday Gift | ucup-team073# | WA | 0ms | 3764kb | C++20 | 3.5kb | 2024-11-09 11:38:30 | 2024-11-09 11:38:31 |
Judging History
answer
#include<bits/stdc++.h>
#ifdef LOCAL
#define debug(...) printf(__VA_ARGS__)
#define edebug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#define edebug(...)
#endif
#define int ll
#define rep(i, x, y) for(int i = x; i <= y; ++i)
#define nrep(i, x, y) for(int i = x; i >= y; --i)
#define ll long long
#define pii std::pair<int,int>
#define pb emplace_back
#define fi first
#define se second
template <class T>
inline void ckmax(T &a, T b) {
if(a < b) a = b;
}
template <class T>
inline void ckmin(T &a, T b) {
if(a > b) a = b;
}
auto rt_YES = []{puts("YES");};
auto rt_Yes = []{puts("Yes");};
auto rt_NO = []{puts("NO");};
auto rt_No = []{puts("No");};
namespace IO {
#define isdigit(x) (x >= '0' && x <= '9')
inline char gc() {
return getchar();
}
inline bool blank(char ch) {
return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
}
template <class T>
inline void read(T &x) {
double tmp = 1;
bool sign = 0;
x = 0;
char ch = gc();
for(; !isdigit(ch); ch = gc())
if(ch == '-') sign = 1;
for(; isdigit(ch); ch = gc())
x = x * 10 + (ch - '0');
if(ch == '.')
for(ch = gc(); isdigit(ch); ch = gc())
tmp /= 10.0, x += tmp * (ch - '0');
if(sign) x = -x;
}
inline void read(char *s) {
char ch = gc();
for(; blank(ch); ch = gc());
for(; !blank(ch); ch = gc())
*s++ = ch;
*s = 0;
}
inline void read(char &c) {
for(c = gc(); blank(c); c = gc());
}
inline void push(const char &c) {
putchar(c);
}
template <class T>
inline void print(T x) {
if(x < 0) {
x = -x;
push('-');
}
static T sta[35];
T top = 0;
do {
sta[top++] = x % 10;
x /= 10;
} while(x);
while(top)
push(sta[--top] + '0');
}
template <class T>
inline void print(T x, char lastChar) {
print(x);
push(lastChar);
}
}
using namespace IO;
// std::stack<int>s;
char S[500010];
int l1,r1,l2,r2,e;
void solve(){
int n,t=0;
scanf("%s",S);n=strlen(S);
e=1;
l1=r1=l2=r2=-1;
rep(i,0,n-1){
int a=S[i]-'0';
int L1=-1,R1=-1,L2=-1,R2=-1,E=-1;
if(a==2){
if(l1>0)L2=l1-1,R2=r1+1;
if(l2>0)L1=l2-1,R1=r2+1;
if(L1==0||L2==0)E=1;
if(L1==0)L1=2;
if(L2==0)L2=2;
if(e==1&&l2<0)L1=R1=1;
if(e==1&&l1<0)L2=R2=1;
}
else if(a==1){
if(l1>0){
L2=l1-1,R2=r1-1;
if(L2==0)E=1,ckmax(L2,2ll);
if(R2==0)L2=R2=-1;
}
if(e==1){
L1=R1=1;
}
if(l2>0){
ckmin(L1,l2+1);
ckmax(R1,r2+1);
}
}
else{
if(l2>0){
L1=l2-1,R1=r2-1;
if(L1==0)E=1,ckmax(L1,2ll);
if(R1==0)L1=R1=-1;
}
if(e==1){
L2=R2=1;
}
if(l1>0){
ckmin(L2,l1+1);
ckmax(R2,r1+1);
}
}
l1=L1,r1=R1,l2=L2,r2=R2,e=E;
debug("%lld %lld %lld %lld %lld\n",l1,r1,l2,r2,e);
}
int ans=1e9;
if(e==1)ans=0;
if(l1>0)ckmin(ans,l1);
if(l2>0)ckmin(ans,l2);
print(ans,'\n');
// for(int i:a)debug("%lld ",i);debug("\n");
}
signed main() {
clock_t c1 = clock();
#ifdef LOCAL
freopen("in.in", "r", stdin);
freopen("out.out", "w", stdout);
#endif
//------------------------------------------------------------------
int t;read(t);while(t--)solve();
//------------------------------------------------------------------
end:
std::cerr << "Time : " << clock() - c1 << " ms" << std::endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3764kb
input:
5 0110101 01020102 0000021111 1012121010 0100202010
output:
1000000000 1000000000 0 1000000000 1000000000
result:
wrong answer 1st numbers differ - expected: '3', found: '1000000000'