Problems
Solution
A
#pragma GCC optimize(2)
#include<set>
#include<map>
#include<ctime>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rint register int
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
const int N=5e4+5;
int T,n;
int a[N];
int main()
{
// freopen("1.in","r",stdin);
int i;
scanf("%d",&T);
while(T--) {
scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
if(a[1]+a[2]<=a[n])
printf("1 2 %d
",n);
else printf("-1
");
}
return 0;
}
B
#pragma GCC optimize(2)
#include<set>
#include<map>
#include<ctime>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rint register int
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
const int N=256;
int T,n;
char a[N];
vector<int> v;
int main()
{
// freopen("1.in","r",stdin);
int i;
scanf("%d",&T);
while(T--) {
scanf("%s",a+1);
n=strlen(a+1);
v.clear();
int cnt=0;
for(i=1;i<=n;i++) {
if(a[i]=='1') cnt++;
else {
if(cnt>0) v.push_back(cnt);
cnt=0;
}
}
if(cnt>0) v.push_back(cnt);
sort(v.begin(),v.end(),greater<int>());
int ans=0;
for(i=0;i<(int)v.size();i+=2)
ans+=v[i];
printf("%d
",ans);
}
return 0;
}
C
//#pragma GCC optimize(2)
#include<set>
#include<map>
#include<ctime>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rint register int
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
const int N=1e5+5;
int T,n;
char c[N];
int a[N],p[N];
LL f[N];
map<int,int> M;
void calc()
{
int cha=0;
M.clear();
for(int i=1;i<=n;i++) {
if(a[i]==0) p[i]=i;
else if(M.count(-a[i]-cha))
p[i]=M[-a[i]-cha];
cha+=a[i];
M[a[i]-cha]=i;
}
return;
}
int main()
{
// freopen("1.in","r",stdin);
int i;
scanf("%d",&T);
while(T--) {
scanf("%d",&n);
scanf("%s",c+1);
for(i=1;i<=n;i++)
a[i]=(c[i]-'0')-1;
memset(p,0,sizeof p);
memset(f,0,sizeof f);
calc();
for(i=1;i<=n;i++) {
if(p[i]!=0)
f[i]=f[p[i]-1]+1;
}
LL ans=0;
for(i=1;i<=n;i++) ans+=f[i];
cout<<ans<<endl;
}
return 0;
}