이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
/*typedef __uint128_t L;
struct FastMod {
ull b, m;
FastMod(ull b) : b(b), m(ull((L(1) << 64) / b)) {}
ull reduce(ull a) {
ull q = (ull)((L(m) * a) >> 64);
ull r = a - q * b; // can be proven that 0 <= r < 2*b
return r >= b ? r - b : r;
}
};
FastMod FM(2);*/
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << H;
debug_out(T...);
}
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)
#define F first
#define S second
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 500 + 10;
const int mod = 1e9 + 7;
int n, dp[maxn][maxn << 1], C[maxn][maxn], CC[maxn << 1][maxn], f[maxn << 1][maxn], inv[maxn], a[maxn], b[maxn];
vector<int> num;
int add(int x, int y){
int res = x + y;
if (res >= mod) return res - mod;
if (res < 0) return res + mod;
return res;
}
int pwr(int a, int b){
int res = 1;
for (; b; b>>=1, a = 1ll * a * a % mod) if (b & 1) res = 1ll * res * a % mod;
return res;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++){
cin >> a[i] >> b[i];
num.push_back(a[i]);
num.push_back(b[i]+1);
}
num.push_back(0);
sort(all(num));
num.resize(distance(num.begin(), unique(all(num))));
for (int i = 1; i <= n; i++){
inv[i] = pwr(i, mod-2);
}
for (int i = 0; i <= n; i++) C[i][0] = 1;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= n; j++){
C[i][j] = add(C[i-1][j-1], C[i-1][j]);
}
}
for (int i = 0; i + 1 < num.size(); i++){
int tmp = num[i+1] - num[i];
for (int j = 1; j <= n; j++){
if (j > tmp) continue;
CC[i][j] = 1;
for (int k = 1; k <= j; k++){
CC[i][j] = 1ll * CC[i][j] * (tmp - k + 1) % mod * inv[k] % mod;
}
}
}
for (int i = 0; i + 1 < num.size(); i++){
int tmp = num[i+1] - num[i];
for (int j = 1; j <= n; j++){
for (int k = 1; k <= j; k++){
f[i][j] = add(f[i][j], 1ll * CC[i][k] * C[j-1][k-1] % mod);
}
}
}
for (int i = 0; i + 1 < num.size(); i++) dp[0][i] = 1;
for (int i = 1; i <= n; i++){
for (int j = 1; j + 1 < num.size(); j++){
dp[i][j] = dp[i][j-1];
if (a[i] > num[j] || b[i] < num[j]) continue;
int cnt = 1;
for (int k = i-1; ~k; k--){
dp[i][j] = add(dp[i][j], 1ll * dp[k][j-1] * f[j][cnt] % mod);
if (a[k] <= num[j] && num[j] <= b[k]) cnt++;
}
}
}
int ans = 0;
for (int i = 1; i <= n; i++){
ans = add(ans, dp[i][num.size()-2]);
}
cout << ans << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
boat.cpp: In function 'int main()':
boat.cpp:83:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | for (int i = 0; i + 1 < num.size(); i++){
| ~~~~~~^~~~~~~~~~~~
boat.cpp:93:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
93 | for (int i = 0; i + 1 < num.size(); i++){
| ~~~~~~^~~~~~~~~~~~
boat.cpp:94:7: warning: unused variable 'tmp' [-Wunused-variable]
94 | int tmp = num[i+1] - num[i];
| ^~~
boat.cpp:103:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
103 | for (int i = 0; i + 1 < num.size(); i++) dp[0][i] = 1;
| ~~~~~~^~~~~~~~~~~~
boat.cpp:105:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
105 | for (int j = 1; j + 1 < num.size(); j++){
| ~~~~~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |