제출 #588613

#제출 시각아이디문제언어결과실행 시간메모리
588613messiuuuuuBoat (APIO16_boat)C++14
100 / 100
474 ms2392 KiB
#include<bits/stdc++.h> #define task "C" #define ll long long #define ld long double #define fi first #define se second #define pb push_back using namespace std; const int MAXN = 1e3 + 5; const ll INF = 1e18 + 5; const int MOD = 1e9 + 7; int n, a[MAXN], b[MAXN]; vector<int> num; void Input() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i] >> b[i]; num.pb(a[i]); num.pb(b[i] + 1); } } int l[MAXN]; int dp[MAXN][MAXN]; void add(int& a, int b) { a += b; if (a > MOD) a -= MOD; } int inv[MAXN]; void Solve() { inv[1] = 1; for (int i = 2; i < MAXN; i++) inv[i] = 1ll * (MOD - MOD / i) * inv[MOD % i] % MOD; sort(num.begin(), num.end()); num.erase(unique(num.begin(), num.end()), num.end()); for (int i = 1; i < num.size(); i++) { l[i] = num[i] - num[i - 1]; } for (int i = 1; i <= n; i++) { a[i] = upper_bound(num.begin(), num.end(), a[i]) - num.begin(); b[i] = upper_bound(num.begin(), num.end(), b[i]) - num.begin(); } for (int i = 0; i < num.size(); i++) dp[0][i] = 1; for (int i = 1; i <= n; i++) { dp[i][0] = 1; for (int j = a[i]; j <= b[i]; j++) { dp[i][j] = (1ll * dp[i - 1][j - 1] * l[j]) % MOD; int cnt = 1; int sl = l[j] - 1; for (int k = i - 1; k; k--) { if (a[k] <= j && j <= b[k]) { cnt++; sl = 1ll * sl * (l[j] + cnt - 2) % MOD * inv[cnt] % MOD; if (!sl) break; add(dp[i][j], 1ll * dp[k - 1][j - 1] * sl % MOD); } } } for (int j = 1; j < num.size(); j++) { add(dp[i][j], (1ll * dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + MOD) % MOD); } } cout << (dp[n][(int)num.size() - 1] - 1 + MOD) % MOD; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); if (fopen(task".INP","r")) { freopen(task".INP","r",stdin); //freopen(task".OUT","w",stdout); } Input(); Solve(); }

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

boat.cpp: In function 'void Solve()':
boat.cpp:46:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for (int i = 1; i < num.size(); i++)
      |                     ~~^~~~~~~~~~~~
boat.cpp:55:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     for (int i = 0; i < num.size(); i++)
      |                     ~~^~~~~~~~~~~~
boat.cpp:78:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |         for (int j = 1; j < num.size(); j++)
      |                         ~~^~~~~~~~~~~~
boat.cpp: In function 'int main()':
boat.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...