Submission #53989603
Source Code Expand
// LUOGU_RID: 160595055
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=1e6+5,M=(1<<20)+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(181766);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
#ifdef LOCAL
#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
#else
#define gdb(...) void()
#endif
}using namespace Debug;
int n,A[N],mi[N];char s[N];
int calc(int lim){
int mx=0,cnt=0;
for(int i=1;i<=n;i++){
if(s[i]=='?'&&mi[i]-2*(cnt+1)>=lim) cnt++;
mx=max(mx,A[i]-2*cnt);
}
// gdb(lim,mx);
return mx-lim;
}
void Solve(){
int i,j;scanf("%s",s+1);n=strlen(s+1);
for(i=1;i<=n;i++) A[i]=A[i-1]+(s[i]=='0'?-1:1);
mi[n+1]=INF;for(i=n;~i;i--) mi[i]=min(mi[i+1],A[i]);
printf("%d\n",min(calc(mi[0]),calc(mi[0]-1)));
}
int main(){
int t=1;
// scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
Submission Info
| Submission Time |
|
| Task |
B - 01 Unbalanced |
| User |
fangxintong |
| Language |
C++ 17 (gcc 12.2) |
| Score |
800 |
| Code Size |
1528 Byte |
| Status |
AC |
| Exec Time |
18 ms |
| Memory |
12808 KiB |
Compile Error
Main.cpp: In function ‘void Solve()’:
Main.cpp:39:15: warning: unused variable ‘j’ [-Wunused-variable]
39 | int i,j;scanf("%s",s+1);n=strlen(s+1);
| ^
Main.cpp:39:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
39 | int i,j;scanf("%s",s+1);n=strlen(s+1);
| ~~~~~^~~~~~~~~~
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
800 / 800 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt |
| All |
00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt, 01-36.txt, 01-37.txt, 01-38.txt, 01-39.txt, 01-40.txt, 01-41.txt, 01-42.txt, 01-43.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00-sample-01.txt |
AC |
2 ms |
4032 KiB |
| 00-sample-02.txt |
AC |
1 ms |
3820 KiB |
| 00-sample-03.txt |
AC |
1 ms |
3880 KiB |
| 01-01.txt |
AC |
1 ms |
4032 KiB |
| 01-02.txt |
AC |
18 ms |
12768 KiB |
| 01-03.txt |
AC |
17 ms |
12808 KiB |
| 01-04.txt |
AC |
17 ms |
12520 KiB |
| 01-05.txt |
AC |
17 ms |
12748 KiB |
| 01-06.txt |
AC |
17 ms |
12688 KiB |
| 01-07.txt |
AC |
17 ms |
12768 KiB |
| 01-08.txt |
AC |
9 ms |
12748 KiB |
| 01-09.txt |
AC |
17 ms |
12688 KiB |
| 01-10.txt |
AC |
9 ms |
12592 KiB |
| 01-11.txt |
AC |
9 ms |
12760 KiB |
| 01-12.txt |
AC |
10 ms |
12528 KiB |
| 01-13.txt |
AC |
10 ms |
12592 KiB |
| 01-14.txt |
AC |
10 ms |
12684 KiB |
| 01-15.txt |
AC |
10 ms |
12596 KiB |
| 01-16.txt |
AC |
10 ms |
12596 KiB |
| 01-17.txt |
AC |
10 ms |
12656 KiB |
| 01-18.txt |
AC |
10 ms |
12652 KiB |
| 01-19.txt |
AC |
10 ms |
12748 KiB |
| 01-20.txt |
AC |
9 ms |
12764 KiB |
| 01-21.txt |
AC |
10 ms |
12692 KiB |
| 01-22.txt |
AC |
10 ms |
12524 KiB |
| 01-23.txt |
AC |
10 ms |
12704 KiB |
| 01-24.txt |
AC |
11 ms |
12520 KiB |
| 01-25.txt |
AC |
10 ms |
12592 KiB |
| 01-26.txt |
AC |
10 ms |
12764 KiB |
| 01-27.txt |
AC |
9 ms |
12600 KiB |
| 01-28.txt |
AC |
17 ms |
12760 KiB |
| 01-29.txt |
AC |
12 ms |
12764 KiB |
| 01-30.txt |
AC |
9 ms |
12592 KiB |
| 01-31.txt |
AC |
10 ms |
12676 KiB |
| 01-32.txt |
AC |
10 ms |
12804 KiB |
| 01-33.txt |
AC |
10 ms |
12664 KiB |
| 01-34.txt |
AC |
9 ms |
12748 KiB |
| 01-35.txt |
AC |
10 ms |
12700 KiB |
| 01-36.txt |
AC |
9 ms |
12708 KiB |
| 01-37.txt |
AC |
9 ms |
12536 KiB |
| 01-38.txt |
AC |
10 ms |
12764 KiB |
| 01-39.txt |
AC |
10 ms |
12804 KiB |
| 01-40.txt |
AC |
10 ms |
12692 KiB |
| 01-41.txt |
AC |
9 ms |
12704 KiB |
| 01-42.txt |
AC |
9 ms |
12660 KiB |
| 01-43.txt |
AC |
10 ms |
12808 KiB |