Submission #399978

# Submission time Handle Problem Language Result Execution time Memory
399978 2021-05-07T02:29:29 Z jeqcho Boat (APIO16_boat) C++17
0 / 100
4 ms 4300 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpi;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define pb push_back
#define rsz resize
#define sz(x) int(x.size())
#define all(x) begin(x), end(x)
#define fi first
#define se second

// subtask 1 and 2

int const N=5e2+3;
ll a[N],b[N];
ll dp[N][2*N];
ll mod =1e9+7;

ll aps(ll n, ll d)
{
	return n * (2*1 + (n-1)*d) / 2;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n;
	cin>>n;
	set<int> st;
	F0R(i,n)
	{
		cin>>a[i]>>b[i];
		--a[i];
		st.insert(a[i]);
		st.insert(b[i]);
	}
	st.insert(0);
	vi v(all(st));
	map<ll,ll>mp;
	F0R(i,sz(st))
	{
		mp[v[i]]=i;
	}
	F0R(i,n)
	{
		a[i]=mp[a[i]];
		b[i]=mp[b[i]];
	}
	F0R(j,sz(st)+1)
	{
		dp[0][j]=1;
	}
	dp[0][0]=0;
	F0R(i,n)
	{
		F0R(j,sz(st))
		{
			dp[i+1][j+1]=dp[i][j+1]-dp[i][j];
		}
		FOR(j,a[i]+1,b[i]+1)
		{
			ll l = v[j]-v[j-1];
			F0R(k,l)
			{
				ll add = aps(l-k,k) * dp[i-k][j];
				add%=mod;
				dp[i+1][j+1]+=add;
				dp[i+1][j+1]%=mod;
			}
		}
		F0R(j,sz(st))
		{
			dp[i+1][j+1]+=dp[i+1][j];
		}
	}
	ll ans=dp[n][sz(st)]-1;
	cout<<ans<<'\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 456 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4300 KB Output isn't correct
2 Halted 0 ms 0 KB -