# Educational Codeforces Round 82 (Rated for Div. 2)

## D.Fill The Bag

#### 题解

#include<bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long LL;
typedef pair<int,int> PII;
#define X first
#define Y second
{
LL x=0,f=1;char c=getchar();
while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c)){x=x*10+c-'0';c=getchar();}
return x*f;
}
int T,m,have[70];
LL n,t,sum;
int main()
{
while(T--)
{
mem(have,0);
LL ans=0; sum=0;
for(int i=1;i<=m;i++)
{
sum+=t;
int cnt=-1;
while(t)cnt++,t>>=1;
have[cnt]++;
}
if(sum<n)
{
printf("-1\n");
continue;
}
int i=0;
while(n)
{
if(n&1ll)
{
if(have[i])have[i]--;
else
{
for(int j=i+1;j<60;j++)
if(have[j])
{
have[j]--;
while(j>i)have[--j]++,ans++;
break;
}
}
}
have[i+1]+=have[i]/2;
n>>=1ll;i++;
}
printf("%lld\n",ans);
}
return 0;
}

## Erase Subsequences

#### 题解

shit为什么我写的题解全没了！！！！

#include<bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long LL;
typedef pair<int,int> PII;
#define X first
#define Y second
{
int x=0,f=1;char c=getchar();
while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c)){x=x*10+c-'0';c=getchar();}
return x*f;
}
const int maxl=410;
int T;
char s[maxl],t[maxl];
int dp[maxl][maxl];
int main()
{
while(T--)
{
scanf("%s%s",s+1,t+1);
int l1=strlen(s+1),l2=strlen(t+1);
bool ok=0;
for(int k=1;k<=l2 && !ok;k++)//第一段范围1~k,第二段k+1~l2
{
mem(dp,-1);//dp[i][j]表示s匹配到i，第一段匹配到j时候第二段的最远匹配
for(int i=0;i<=l1;i++)dp[i][0]=0;
for(int i=0;i<l1;i++)
for(int j=0;j<=k;j++)
{
if(dp[i][j]==-1)continue;
dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
if(s[i+1]==t[j+1])dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]);
if(s[i+1]==t[dp[i][j]+1+k])dp[i+1][j]=max(dp[i+1][j],dp[i][j]+1);
}
for(int i=0;i<=l1;i++)if(dp[i][k]==l2-k)ok=1;
}
if(!ok)printf("NO\n");
else printf("YES\n");
}
return 0;
}

## Number of Components

#### 题解

#include<bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long LL;
typedef pair<int,int> PII;
#define X first
#define Y second
{
int x=0,f=1;char c=getchar();
while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c)){x=x*10+c-'0';c=getchar();}
return x*f;
}
const int maxn=310;
int n,m,Q,a[maxn][maxn],f[maxn*maxn],x,y,c,all,dx[4]={0,1,0,-1},dy[4]={1,0,-1,0},ans[2000010];
bool legal(int x,int y){return x>=0 && x<n && y>=0 && y<m;}
int getf(int x){return f[x]==x ? x : f[x]=getf(f[x]);}
bool merge(int x,int y)
{
int a=getf(x),b=getf(y);
return a!=b ? f[a]=b,true : false;
}
void calc(vector<PII> &col,int t)
{
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)a[i][j]=0,f[i*m+j]=i*m+j;
for(auto it: col)
{
x=it.X/m,y=it.X%m;
a[x][y]=1;
int block=1;
for(int i=0;i<4;i++)
{
int nx=x+dx[i],ny=y+dy[i];
if(legal(nx,ny) && a[nx][ny]==1)
block-=merge(x*m+y,nx*m+ny);
}
if(it.Y==Q+1)ans[it.Y]+=t*block;
}
}
int main()
{
for(int i=1;i<=Q;i++)
{
int pos=x*m+y;
if(i==Q)all=c;
del[a[x][y]].push_back(make_pair(pos,i));
a[x][y]=c;
}
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
del[a[i][j]].push_back(make_pair(i*m+j,Q+1));
for(int i=0;i<=all;i++)reverse(del[i].begin(),del[i].end());