Esempio n. 1
0
bool isValid(long long g) {
  // cout << "G: " << g << endl;
  MaxQueue Q;
  long long l = max(d - g, 1ll), r = d + g;
  queue<State> wait;
  wait.push(State{0ll, 0ll});
  long long best = 0;
  for (State p: points) {
    // cout << "===" << i << endl;
    long long L = p.x - r, R = p.x - l;
    while (wait.size() != 0 && wait.front().x <= R) {
      Q.push(wait.front());
      wait.pop();
    }
    while (Q.size() != 0 && Q.front().x < L) Q.pop();
    if (Q.size() != 0) {
      // cout << "Push: " << Q.max() + p.s << endl;
      wait.push(State{p.x, Q.max() + p.s});
      best = max(best, Q.max() + p.s);
    }
  }
  return best >= k;
}
Esempio n. 2
0
int solve(){
  MaxQueue Q;
  for (int i = 1; i <= K; i++){
    if (d[i] == 1){
      for (int y = 1; y <= M; y++){
        Q.clear();
        for (int x = N, ii = 1; x >= 1; x--, ii++){
          while(Q.size() > t[i] - s[i] + 1) Q.pop();
          if (grid[x][y] == 'x'){Q.clear(); continue;}
          dp[i][x][y] = dp[i - 1][x][y]; 
          if (Q.size()) dp[i][x][y] = max(dp[i][x][y], Q.max() + ii);
          if (dp[i - 1][x][y]) Q.push(dp[i - 1][x][y] - ii); 
          else Q.push(-0x1f1f1f1f);
        }
      }
    }else if (d[i] == 2){
      for (int y = 1; y <= M; y++){
        Q.clear();
        for (int x = 1, ii = 1; x <= N; x++, ii++){
          while(Q.size() > t[i] - s[i] + 1) Q.pop();
          if (grid[x][y] == 'x'){Q.clear(); continue;}
          dp[i][x][y] = dp[i - 1][x][y]; 
          if (Q.size()) dp[i][x][y] = max(dp[i][x][y], Q.max() + ii);
          if (dp[i - 1][x][y]) Q.push(dp[i - 1][x][y] - ii); 
          else Q.push(-0x1f1f1f1f);
        }
      }
    }else if (d[i] == 3){
      for (int x = 1; x <= N; x++){
        Q.clear();
        for (int y = M, ii = 1; y >= 1; y--, ii++){ 
          while(Q.size() > t[i] - s[i] + 1) Q.pop();
          if (grid[x][y] == 'x'){Q.clear(); continue;}
          dp[i][x][y] = dp[i - 1][x][y]; 
          if (Q.size()) dp[i][x][y] = max(dp[i][x][y], Q.max() + ii);
          if (dp[i - 1][x][y]) Q.push(dp[i - 1][x][y] - ii); 
          else Q.push(-0x1f1f1f1f);
        }
      }
    }else if (d[i] == 4){
      for (int x = 1; x <= N; x++){
        Q.clear();
        for (int y = 1, ii = 1; y <= M; y++, ii++){ 
          //cout << Q.size() << ", " << t[i] << ", " << s[i] << "=>" << (Q.size() ? Q.max(): 0) << endl;
          while(Q.size() > t[i] - s[i] + 1) Q.pop();
          if (grid[x][y] == 'x'){Q.clear(); continue;}
          dp[i][x][y] = dp[i - 1][x][y]; 
          if (Q.size()) dp[i][x][y] = max(dp[i][x][y], Q.max() + ii);
          if (dp[i - 1][x][y]) Q.push(dp[i - 1][x][y] - ii);
          else Q.push(-0x1f1f1f1f);
        }
      }
    }
  }
  int ans = 0;
  for (int x = 1; x <= N; x++){
    for (int y = 1; y <= M; y++){
      ans = max(ans, dp[K][x][y]);
    }
  }
  return ans - 1;
}