Submission #305869

# Submission time Handle Problem Language Result Execution time Memory
305869 2020-09-24T03:40:54 Z couplefire Boat (APIO16_boat) C++17
27 / 100
11 ms 4480 KB
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;

const int N = 503;
const int p = 1000000007;

int l[N], a[N], b[N], H[N << 1], cnt = 0, n, f[N][N << 1], ni[N];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d%d", a + i, b + i);
		H[++cnt] = a[i];
		H[++cnt] = ++b[i];
	}
	
	stable_sort(H + 1, H + cnt + 1);
	cnt = unique(H + 1, H + cnt + 1) - H;
	
	for (int i = 1; i <= n; ++i) {
		a[i] = lower_bound(H + 1, H + cnt, a[i]) - H;
		b[i] = lower_bound(H + 1, H + cnt, b[i]) - H;
	}
	
	cnt -= 2;
	for (int i = 1; i <= cnt; ++i)
		l[i] = H[i + 1] - H[i];
	
	ni[1] = 1;
	for (int i = 2; i <= n; ++i)
		ni[i] = 1ll * (p - p / i) * ni[p % i] % p;
	
	for (int i = 0; i <= cnt; ++i) f[0][i] = 1;
	for (int i = 1; i <= n; ++i) {
		for (int j = a[i], up = b[i]; j < up; ++j) {
			int C = l[j], r = l[j], c = 1;
			for (int k = i - 1; k >= 0; --k) {
				(f[i][j] += 1ll * f[k][j - 1] * C % p) %= p;
				if (a[k] <= j && j < b[k]) {
					++r; ++c;
					C = 1ll * C * r % p * ni[c] % p;
				}
			}
		}
		
		for (int j = 2; j <= cnt; ++j)
			(f[i][j] += f[i][j - 1]) %= p;
	}
	
	int ans = 0;
	for (int i = 1; i <= n; ++i) (ans += f[i][cnt]) %= p;
	printf("%d\n", ans);
	return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   13 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
boat.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 |   scanf("%d%d", a + i, b + i);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 11 ms 4480 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 11 ms 4480 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 Correct 4 ms 768 KB Output is correct
2 Correct 3 ms 768 KB Output is correct
3 Correct 3 ms 768 KB Output is correct
4 Correct 4 ms 768 KB Output is correct
5 Correct 4 ms 768 KB Output is correct
6 Correct 6 ms 768 KB Output is correct
7 Correct 6 ms 768 KB Output is correct
8 Correct 6 ms 768 KB Output is correct
9 Correct 6 ms 768 KB Output is correct
10 Correct 6 ms 768 KB Output is correct
11 Correct 4 ms 768 KB Output is correct
12 Correct 3 ms 768 KB Output is correct
13 Correct 3 ms 768 KB Output is correct
14 Correct 3 ms 768 KB Output is correct
15 Correct 4 ms 768 KB Output is correct
16 Correct 3 ms 768 KB Output is correct
17 Correct 2 ms 768 KB Output is correct
18 Correct 3 ms 768 KB Output is correct
19 Correct 3 ms 768 KB Output is correct
20 Correct 3 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 11 ms 4480 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -