# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
255699 | Mercenary | Boat (APIO16_boat) | C++14 | 581 ms | 4476 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#define pb push_back
#define mp make_pair
#define taskname "A"
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double ld;
typedef pair<int,int> ii;
typedef tree <ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int maxn = 500 + 5;
const int mod = 1e9 + 7;
int n , a[maxn] , b[maxn];
int dp[maxn][maxn * 2];
int c[maxn * 2][maxn];
vector<int> val;
int Pow(int i , int j){
if(j == 0)return 1;
int r = Pow(i , j / 2);
if(j & 1)return (ll)r * r % mod * i % mod;
return (ll)r * r % mod;
}
int r[maxn];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
if(fopen(taskname".INP","r")){
freopen(taskname".INP", "r",stdin);
freopen(taskname".OUT", "w",stdout);
}
cin >> n;
for(int i = 1 ; i <= n ; ++i){
cin >> a[i] >> b[i];--a[i];
val.pb(a[i]);val.pb(b[i]);
r[i] = Pow(i , mod - 2);
}
sort(val.begin(),val.end());val.erase(unique(val.begin(),val.end()),val.end());
for(int i = 0 ; i < val.size() ; ++i){
dp[0][i] = 1;
if(i > 0){
int len = val[i] - val[i - 1];
c[i][0] = 1;
for(int j = 1 ; j <= n ; ++j){
c[i][j] = (ll)c[i][j - 1] * (len + j - 1) % mod * r[j] % mod;
}
}
}
for(int i = 1 ; i <= n ; ++i){
dp[i][0] = 1;
for(int j = 1 ; j < val.size() ; ++j){
int sum = 0;
dp[i][j] = dp[i][j - 1];
for(int k = i ; k >= 1 ; --k){
if(a[k] < val[j] && val[j] <= b[k]){
dp[i][j] = (dp[i][j] + (ll)dp[k - 1][j - 1] * c[j][++sum]) %mod;
}
}
// cout << dp[i][j] << " ";
}
// cout << endl;
}
cout << dp[n][val.size() - 1] - 1;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |