Submission #305869

#TimeUsernameProblemLanguageResultExecution timeMemory
305869couplefireBoat (APIO16_boat)C++17
27 / 100
11 ms4480 KiB
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; const int N = 503; const int p = 1000000007; int l[N], a[N], b[N], H[N << 1], cnt = 0, n, f[N][N << 1], ni[N]; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d%d", a + i, b + i); H[++cnt] = a[i]; H[++cnt] = ++b[i]; } stable_sort(H + 1, H + cnt + 1); cnt = unique(H + 1, H + cnt + 1) - H; for (int i = 1; i <= n; ++i) { a[i] = lower_bound(H + 1, H + cnt, a[i]) - H; b[i] = lower_bound(H + 1, H + cnt, b[i]) - H; } cnt -= 2; for (int i = 1; i <= cnt; ++i) l[i] = H[i + 1] - H[i]; ni[1] = 1; for (int i = 2; i <= n; ++i) ni[i] = 1ll * (p - p / i) * ni[p % i] % p; for (int i = 0; i <= cnt; ++i) f[0][i] = 1; for (int i = 1; i <= n; ++i) { for (int j = a[i], up = b[i]; j < up; ++j) { int C = l[j], r = l[j], c = 1; for (int k = i - 1; k >= 0; --k) { (f[i][j] += 1ll * f[k][j - 1] * C % p) %= p; if (a[k] <= j && j < b[k]) { ++r; ++c; C = 1ll * C * r % p * ni[c] % p; } } } for (int j = 2; j <= cnt; ++j) (f[i][j] += f[i][j - 1]) %= p; } int ans = 0; for (int i = 1; i <= n; ++i) (ans += f[i][cnt]) %= p; printf("%d\n", ans); return 0; }

Compilation message (stderr)

boat.cpp: In function 'int main()':
boat.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   13 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
boat.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 |   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...