# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
206218 |
2020-03-02T17:42:08 Z |
mraron |
Boat (APIO16_boat) |
C++14 |
|
22 ms |
12536 KB |
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair
#ifndef ONLINE_JUDGE
# define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
# define LOG(x) ((void)0)
#endif
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const double PI=3.1415926535897932384626433832795;
const ll INF = 1LL<<62;
const ll MINF = -1LL<<62;
template<typename T> T getint() {
T val=0;
char c;
bool neg=false;
while((c=gc()) && !(c>='0' && c<='9')) {
neg|=c=='-';
}
do {
val=(val*10)+c-'0';
} while((c=gc()) && (c>='0' && c<='9'));
return val*(neg?-1:1);
}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)
int n;
vector<int> lst;
int a[501], b[501];
int ways[1001][1001];
map<int,int> conv;
map<int,int> iconv;
const ll mod=1e9+7;
ll dp[501][1001];
ll fakt[1001];
ll ifakt[1001];
ll fp(ll a, ll b) {
if(b==0) return 1;
ll fele=fp(a,b/2);
ll ans=fele*fele%mod;
if(b&1) ans=ans*a%mod;
return ans;
}
ll choose(ll a, ll b) {
if(a<b) return 0;
return fakt[a]*ifakt[b]*ifakt[a-b];
}
ll calc(int i, int j) {
if(j<=0) return 0;
if(dp[i][j]!=-1) return dp[i][j];
if(j<a[i]) return 0;
ll ans=(calc(i, j-1)+ways[j-1][j])%mod;
for(int k=i-1;k>=0;--k) {
ans=(ans+calc(k,j-1)*choose(ways[j-1][j], i-k-1)%mod);
}
return dp[i][j]=ans;
}
int main() {
IO;
fakt[0]=1;
for(int i=1;i<1001;++i) {
fakt[i]=fakt[i-1]*i%mod;
ifakt[i]=fp(fakt[i], mod-2);
}
cin>>n;
for(int i=0;i<n;++i) {
cin>>a[i]>>b[i];
lst.push_back(a[i]);
lst.push_back(b[i]);
}
sort(all(lst));
lst.resize(distance(lst.begin(), unique(all(lst))));
int ind=0;
for(auto i:lst) {
conv[i]=ind++;
iconv[ind-1]=i;
}
for(int i=0;i<n;++i) {
a[i]=conv[a[i]];
b[i]=conv[b[i]];
}
for(int i=0;i<lst.size();++i) {
for(int j=i;j<lst.size();++j) {
ways[conv[lst[i]]][conv[lst[j]]]=lst[j]-lst[i]+1;
}
}
memset(dp, -1, sizeof dp);
ll ans=-1;
for(int i=0;i<n;++i) {
ans+=calc(i, lst.size()-1);
ans%=mod;
}
if(ans<0) ans+=mod;
cout<<ans<<"\n";
return 0;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:131:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<lst.size();++i) {
~^~~~~~~~~~~
boat.cpp:132:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=i;j<lst.size();++j) {
~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
22 ms |
12536 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
22 ms |
12536 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
15 ms |
10104 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
22 ms |
12536 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |