LOADING

加载过慢请开启缓存,浏览器默认开启

daily 2

2023/6/13 daily

CF 747D

void solve(){
  int n,k;
  cin>>n>>k;
  vector<int>a(n+1);
  vector<int>snow_range;
  int last_snow=-1;
  int ans=0;
  for(int i=1;i<=n;++i){
    cin>>a[i];
    if(a[i]<0){
        if(last_snow>0)snow_range.push_back(i-last_snow-1);
        last_snow=i;
        ans+=2;
        --k;
    }
  }
  if(k<0){
    cout<<-1<<'\n';
    return;
  }
  sort(snow_range.begin(),snow_range.end());
  for(int r:snow_range){
    if(k>=r){
        k-=r;
        ans-=2;
    }else{
        break;
    }
  }
  cout<<(n-last_snow<=k?ans-1:ans)<<'\n';
  return;
}

CF 750D

const int MOD=1e9+7;
const int MAXN=310;
const int MAXM=33;
int dx[8]={0,-1,-1,-1,0,1,1,1};
int dy[8]={1,1,0,-1,-1,-1,0,1};
int mp[MAXN][MAXN];
int dp[MAXN][MAXN][MAXM][8];
struct node {
  int x,y,depth,dir;  
};
void solve(){
  int n;
  cin>>n;
  vector<int>t(n+1);
  for(int i=1;i<=n;++i)cin>>t[i];
  queue<node>q;
  q.push({152,152,1,2});
  while(!q.empty()){
    auto cur=q.front();
    q.pop();
    if(cur.depth>n||dp[cur.x][cur.y][cur.depth][cur.dir]==1)continue;
    dp[cur.x][cur.y][cur.depth][cur.dir]=1;
    for(int i=1;i<=t[cur.depth];++i){
        cur.x+=dx[cur.dir];
        cur.y+=dy[cur.dir];
        mp[cur.x][cur.y]=1;
    }
    q.push({cur.x,cur.y,cur.depth+1,(cur.dir+1)%8});
    q.push({cur.x,cur.y,cur.depth+1,(cur.dir+7)%8});
  }
  int ans=0;
  for(int i=1;i<MAXN;++i){
    for(int j=1;j<MAXN;++j){
        if(mp[i][j]){
            ++ans;
        }
    }
  }
  cout<<ans<<'\n';
  return;
}