제출 #23490

#제출 시각아이디문제언어결과실행 시간메모리
23490NirjhorBoat (APIO16_boat)C++14
58 / 100
2000 ms7352 KiB
#include <bits/stdc++.h> 

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;

const int N = 505;
const int M = 1005;
const int MOD = 1e9 + 7;

vector <pii> v;
vector <int> z[M];
int n, m, a[N], b[N];
int x[M], y[M], dp[N][M];
int sz[M], wide[M];
int comb[M][N], inverse[N];
int counter = 1;

int bigMod (int a, int e) {
  if (e == -1) e = MOD - 2;
  int r = 1; while (e) {
    if (e & 1) r = (r * 1ll * a) % MOD;
    a = (a * 1ll * a) % MOD;
    e >>= 1;
  }
  return r;
}

int call (int at, int range) {
  if (at > n or range > m) return 1;
  if (dp[at][range] != -1) return dp[at][range];
  ll ret = call(at, range + 1);
  for (int i = 0, pos = 0; i < sz[range]; ++i) {
    if (z[range][i] < at) {
      ++pos;
      continue;
    }
    // cout << rem << " comb ---> " << comb[range][rem] << endl;
    ret += comb[range][i - pos] * 1ll * call(z[range][i] + 1, range + 1);
    ret %= MOD;
  }
  return dp[at][range] = ret;
}

int nCr (int n, int r) {
  if (n < r) return 0;
  ll res = 1ll;
  for (int i = n, j = 1; j <= r; --i, ++j) {
    res *= 1ll * i, res %= MOD;
    res *= inverse[j], res %= MOD;
  }
  return res;
}

int main (int argc, char const *argv[]) {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d %d", a + i, b + i);
    v.push_back({a[i], 0});
    v.push_back({b[i], 1});
  }
  sort(v.begin(), v.end());
  for (int i = 1; i < n + n; ++i) {
    int one = v[i - 1].second, two = v[i].second;
    int l = v[i - 1].first, r = v[i].first;
    if (!one and !two) {
      --r, ++counter;
      if (l <= r) x[++m] = l, y[m] = r;
    } else if (!one and two) {
      --counter;
      // cout << "yo " << i << " " << m << endl;
      if (l <= r) x[++m] = l, y[m] = r;
    } else if (one and two) {
      ++l, --counter;
      if (l <= r) x[++m] = l, y[m] = r; 
    } else {
      ++l, --r;
      if (counter and l <= r) x[++m] = l, y[m] = r;
      ++counter;
    }
  }
  // cout << m << endl;
  // for (int i = 1; i <= m; ++i) {
  //   cout << x[i] << " " << y[i] << endl;
  // }
  for (int i = 1; i <= m; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (a[j] <= x[i] and y[i] <= b[j]) {
        z[i].push_back(j);
        ++sz[i];
      }
    }
    wide[i] = y[i] - x[i] + 1;
  } 
  for (int i = 1; i < N; ++i) {
    inverse[i] = bigMod(i, -1);
  }
  for (int i = 1; i <= m; ++i) {
    for (int j = 0; j <= n; ++j) {
      comb[i][j] = nCr(wide[i] + j, j + 1);
    }
  }
  // for (int i = 1; i <= m; ++i) {
  //   cout << i << " --> ";
  //   for (int j : z[i]) cout << j << " ";
  //   cout << endl;
  // } 
  memset(dp, -1, sizeof dp);
  // for (int i = 1; i <= n; ++i) {
  //   for (int j = 1; j <= m; ++j) {
  //     cout << "(" << i << ", " << j << ") ---> " << call(i, j) << endl;
  //   }
  // }
  int ans = call(1, 1) + MOD - 1;
  printf("%d\n", ans % MOD);
  return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

boat.cpp: In function 'int main(int, const char**)':
boat.cpp:57:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
                  ^
boat.cpp:59:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", a + i, b + i);
                                 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...