QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#124946#5648. Crossing the RailwaysHongzy#WA 1ms3608kbC++175.4kb2023-07-15 19:54:192023-07-15 19:54:20

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-15 19:54:20]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3608kb
  • [2023-07-15 19:54:19]
  • 提交

answer

#include <bits/stdc++.h>
#define LOG(FMT...) fprintf(stderr, FMT);
#define rep(i, j, k) for(int i = j; i <= k; ++ i)
#define per(i, j, k) for(int i = j; i >= k; -- i)
using namespace std;

#define fs first
#define sc second
#define pb push_back
#define mp make_pair

using db = double;
using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

mt19937 mt(chrono::system_clock::now().time_since_epoch().count());
uniform_int_distribution<ll> ran(0, 1ll << 62);
void ucin() { ios::sync_with_stdio(0); cin.tie(0); }
// uniform_real_distribution<double> dbran;
template<class T> inline void chkmax(T &x, const T &y) { if(x < y) x = y; }
template<class T> inline void chkmin(T &x, const T &y) { if(x > y) x = y; }
inline ll sqr(ll x) { return x * x; }
inline ll cub(ll x) { return x * x * x; }

const int N = 510;
const int INF = 1e9;
const db eps = 1e-5;
#define lt(x, y) ((x) < (y) - eps)
#define leq(x, y) ((x) < (y) + eps)
struct seg {
  int r, a, b;
  bool operator < (const seg &rhs) const {
    if(r != rhs.r) return r < rhs.r;
    return a < rhs.a;
  }
} a[N];
int n, m, s, v, L[12], R[12];
int dp[N*2], X[N*2], Y[N*2];

bool inc(db l, db x, db r) {
  return lt(l, x) && lt(x, r);
}
bool incLL(ll l, ll x, ll r) {
  return l < x && x < r;
}
int find(int y, ll up) { //last <= y
  if(!L[y]) return -1;
  int l = L[y], r = R[y], ans = -1;
  while(l <= r) {
    int mid = (l + r) >> 1;
    if(X[mid] <= up) l = (ans = mid) + 1;
    else r = mid - 1;
  }
  return ans;
}
bool inc(db x1, int y1, db x2, int y2) {
  // assert(lt(x1, x2) && y1 < y2);
  db k = (x2 - x1) / (y2 - y1);
  rep(i, y1, y2) {
    db x0 = k * (i - y1) + x1;
    int z = find(i, ll(x0));
    if(z == -1) continue;
    z = (z + 1) / 2;
    if(inc(a[z].a, x0, a[z].b))
      return true;
  }
  return false;
}
int ans;
void upd(int id, db k, int cur) {
  rep(i, Y[id]+1, m+1) {
    db x0 = k * (i - Y[id]) + X[id];
    if(i == m+1) {
      if(leq(x0, s)) {
        ans = min(ans, cur);
      }
      break;
    }
    int z = find(i, ll(x0));
    if(z == -1) continue;
    int w = z + 1;
    z = (z + 1) / 2;
    if(inc(a[z].a, x0, a[z].b))
      break;
    if(Y[w] == i)
      dp[w] = min(dp[w], cur + 1);
  }
}
void DP(int id, int y0, db k, int cur) {
  per(i, y0, 0) {
    db x0 = k * (i - Y[id]) + X[id];
    if(!i) {
      if(leq(x0, 0))
        cur = min(cur, 0);
      break;
    }
    int z = find(i, ll(x0));
    if(z == -1) continue;
    int w = dp[z];
    z = (z + 1) / 2;
    if(inc(a[z].a, x0, a[z].b))
      break;
    cur = min(cur, w + 2);
  }
  dp[id] = min(dp[id], cur);
  upd(id, k, cur);
}
int main() {
  scanf("%d%d%d%d", &n, &m, &s, &v);
  rep(i, 1, n) {
    int a, b, r;
    scanf("%d%d%d", &a, &b, &r);
    ::a[i] = {r, a, b};
  }
  sort(a + 1, a + n + 1);

  rep(i, 1, 2*n) {
    int y = a[(i + 1) / 2].r;
    int x = i & 1 ? a[(i + 1) / 2].a : a[(i + 1) / 2].b;
    X[i] = x, Y[i] = y;
    if(!L[y]) L[y] = i;
    R[y] = i;
    // printf("(%d, %d)\n", x, y);
  }
  { //start
    db x0 = 0, x2 = (m + 1.0) * v;
    if(!inc(x0, 0, x2, m + 1) && leq(x2, s)) {
      puts("0");
      cerr << "**\n";
      return 0;
    }
  }
  rep(i, 1, 2*n) dp[i] = INF;
  //pass single point
  rep(i, 1, 2*n) {
    db x = X[i];
    int y = Y[i];
    db x2 = x + (m + 1.0 - y) * v;
    db x0 = x - (db)y * v;
    if(leq(0, x0) && leq(x2, s) && !inc(x0, 0, x2, m + 1)) {
      puts("0");
      cerr << "()\n";
      return 0;
    }
  }
  //pass two points
  rep(i, 1, 2*n)
    rep(j, i+1, 2*n)
      if(X[i] < X[j] && Y[i] < Y[j] && (Y[j] - Y[i]) * v <= (X[j] - X[i])) {
        // printf("(%d, %d)!\n", i, j);
        db k = (Y[j] - Y[i]) / db(X[j] - X[i]);
        db x0 = X[i] - Y[i] / k, x2 = X[j] + (m + 1 - Y[j]) / k;
        if(leq(0, x0) && leq(x2, s) && !inc(x0, 0, x2, m + 1)) {
          puts("0");
          cerr << "[]\n";
          return 0;
        }
      }

  ans = INF;
  rep(i, 1, 2*n) {
    int x = X[i], y = Y[i];
    db x0 = x - (db)y * v;
    if(leq(0, x0) && !inc(x0, 0, x, y)) {
      // printf("x0 = %.1f\n", x0);
      dp[i] = 0;
      upd(i, v, 0);
    } else {
      rep(j, 1, i-1) {
        if(x > X[j] && y > Y[j] && (y - Y[j]) * v <= (x - X[j])) {
          db v0 = (y - Y[j]) / db(x - X[j]);
          db x0 = x - (db)y / v0;
          if(leq(0, x0) && !inc(x0, 0, x, y)) {
            dp[i] = 0;
            upd(i, 1 / v0, 0);
            break;
          }
        }
      }
    }
    DP(i, y, v, INF);
    rep(j, 1, i-1) {
      if(x > X[j] && y > Y[j] && (y - Y[j]) * v <= (x - X[j])) {
        if(!inc(X[j], Y[j], x, y)) {
          dp[i] = min(dp[i], dp[j] + 1);
          DP(i, Y[j], (x - X[j]) / db(y - Y[j]), dp[j] + 1);
        }
      }
    }

    if(dp[i] < INF) {
      db x2 = x + (m + 1.0 - y) * v;
      if(leq(x2, s) && !inc(x, y, x2, m + 1)) {
        ans = min(ans, dp[i] + 1);
      } else {
        rep(j, i+1, 2*n) {
          if(x < X[j] && y < Y[j] && (Y[j] - y) * v <= (X[j] - x)) {
            db v0 = (Y[j] - y) / db(X[j] - x);
            db x2 = x + (db)(m + 1 - y) / v0;
            if(leq(x2, s) && !inc(x, y, x2, m + 1)) {
              ans = min(ans, dp[i] + 1);
              break;
            }
          }
        }
      }
    }
  }
  if(ans == INF) ans = -1;
  printf("%d\n", ans);
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3432kb

input:

4 3 5 1
1 2 1
3 4 1
2 3 2
3 4 3

output:

0

result:

ok single line: '0'

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3608kb

input:

3 3 12 2
2 10 1
1 6 2
8 12 3

output:

0

result:

wrong answer 1st lines differ - expected: '2', found: '0'