제출 #139849

#제출 시각아이디문제언어결과실행 시간메모리
139849SaboonBoat (APIO16_boat)C++14
100 / 100
1012 ms6520 KiB
#include <algorithm>
#include <cstring>
#include <cstdio>
using ll = long long;
constexpr int MOD = 1e9 + 7;
inline int quick_pow(int a, int n)
{
	int res = 1;
	while (n)
	{
		if (n & 1)
			res = (ll)res * a % MOD;
		a = (ll)a * a % MOD;
		n >>= 1;
	}
	return res;
}
int lp[505], rp[505], app[1005], dp[1005][505], nxt[1005][505], sum[1005][505], inv[505];
int main()
{
	// freopen("uoj-204.in", "r", stdin);
	int n, cnt = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d%d", lp + i, rp + i);
		app[cnt++] = lp[i];
		app[cnt++] = ++rp[i];
	}
	std::sort(app, app + cnt);
	cnt = std::unique(app, app + cnt) - app;
	for (int i = 0; i < n; i++)
	{
		lp[i] = std::lower_bound(app, app + cnt, lp[i]) - app;
		rp[i] = std::lower_bound(app, app + cnt, rp[i]) - app;
	}
	inv[0] = inv[1] = 1;
	for (int i = 2; i <= n; i++)
		inv[i] = (ll)(MOD - MOD / i) * inv[MOD % i] % MOD;
	dp[0][0] = 1;
	for (int i = 0; i < n; i++)
	{
		memcpy(nxt, dp, sizeof(dp));
		memset(sum, 0, sizeof(sum));
		for (int j = 0; j < cnt; j++)
		{
			for (int k = 0; k <= i; k++)
				sum[j + 1][k] = (sum[j][k] + dp[j][k]) % MOD;
		}
		for (int j = lp[i]; j < rp[i]; j++)
		{
			int len = app[j + 1] - app[j];
			for (int k = 0; k <= i; k++)
			{
				nxt[j][k + 1] = (nxt[j][k + 1] + (ll)dp[j][k] * (len - k) % MOD * inv[k + 1]) % MOD;
				nxt[j][1] = (nxt[j][1] + (ll)sum[j][k] * len) % MOD;
			}
		}
		memcpy(dp, nxt, sizeof(dp));
	}
	int ans = 0;
	for (int i = 0; i < cnt; i++)
	{
		for (int j = 0; j <= n; j++)
			ans = (ans + dp[i][j]) % MOD;
	}
	printf("%d\n", (ans + MOD - 1) % MOD);
	return 0;
}

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

boat.cpp: In function 'int main()':
boat.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
boat.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", lp + i, rp + i);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...