Submission #25559

# Submission time Handle Problem Language Result Execution time Memory
25559 2017-06-23T04:59:33 Z kajebiii Boat (APIO16_boat) C++14
100 / 100
1799 ms 8128 KB
#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REPO(i,n) for(int (i)=1; (i)<=(int)(n); (i)++)
#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 5e2 + 10, MAX_C = MAX_N * 2, MOD = 1e9 + 7;

int N, Nr[MAX_N][2], Dy[2][MAX_C][MAX_N], Sum[MAX_C];
vector<int> Co;
void add(int &a, int b) {
	if((a+=b) >= MOD) a -= MOD;
	if(a<0) a += MOD;
}
int pow(int a, int b) {
	int r = 1, p = a;
	while(b) {
		if(b&1) r = 1ll * r * p % MOD;
		p = 1ll * p * p % MOD;
		b >>= 1;
	}
	return r;
}
int Calc[MAX_C][MAX_N];
int main() {
	cin >> N; 
	REPO(i, N) REP(j, 2) scanf("%d", &Nr[i][j]), Nr[i][j] += j, Co.push_back(Nr[i][j]);
	Co.push_back(0);
	sort(ALL(Co)); Co.erase(unique(ALL(Co)), Co.end());
	REPO(i, N) REP(j, 2) Nr[i][j] = lower_bound(ALL(Co), Nr[i][j]) - Co.begin();

	int cN = SZ(Co);
	for(int i=0; i+1<cN; i++) {
		Calc[i][0] = 1;
		int v = Co[i+1] - Co[i];
		for(int j=1; j<=N; j++)
			Calc[i][j] = 1ll * Calc[i][j-1] * (v-j+1) % MOD * pow(j, MOD-2) % MOD;
	}
	Dy[0][0][0] = Dy[0][0][1] = 1;
	REPO(i, N) {
		int n = i&1, o = 1-n;
		for(int j=0; j<Nr[i][1]-1; j++) {
			if(j) Sum[j] = Sum[j-1]; else Sum[j] = 0;
			Sum[j] = (Sum[j] + Dy[o][j][0]) % MOD;
		}
		for(int k=0; k<=i; k++) for(int j=0; j<cN; j++) Dy[n][j][k] = Dy[o][j][k];
		for(int j=Nr[i][0]; j<Nr[i][1]; j++) {
			for(int k=i; k>=1; k--) {
				add(Dy[n][j][k+1], Dy[n][j][k]);
				add(Dy[n][j][0], 1ll * Dy[n][j][k] * Calc[j][k+1] % MOD);
			}
			add(Dy[n][j][1], Sum[j-1]);
			add(Dy[n][j][0], 1ll * Sum[j-1] * Calc[j][1] % MOD);
		}
		/*
		for(int j=0; j+1<cN; j++) {
			printf("[%d ~ %d]\n", Co[j], Co[j+1]);
			for(int k=0; k<=i; k++) printf("%d ", Dy[n][j][k]); puts("");
		}
		*/
	}
	int ans = 0;
	for(int j=1; j<cN; j++) add(ans, Dy[N&1][j][0]);
	printf("%d\n", ans);
	return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:36:84: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  REPO(i, N) REP(j, 2) scanf("%d", &Nr[i][j]), Nr[i][j] += j, Co.push_back(Nr[i][j]);
                                                                                    ^
# Verdict Execution time Memory Grader output
1 Correct 676 ms 8128 KB Output is correct
2 Correct 719 ms 8128 KB Output is correct
3 Correct 746 ms 8128 KB Output is correct
4 Correct 773 ms 8128 KB Output is correct
5 Correct 673 ms 8128 KB Output is correct
6 Correct 743 ms 8128 KB Output is correct
7 Correct 783 ms 8128 KB Output is correct
8 Correct 809 ms 8128 KB Output is correct
9 Correct 716 ms 8128 KB Output is correct
10 Correct 713 ms 8128 KB Output is correct
11 Correct 789 ms 8128 KB Output is correct
12 Correct 896 ms 8128 KB Output is correct
13 Correct 786 ms 8128 KB Output is correct
14 Correct 713 ms 8128 KB Output is correct
15 Correct 696 ms 8128 KB Output is correct
16 Correct 73 ms 8128 KB Output is correct
17 Correct 89 ms 8128 KB Output is correct
18 Correct 73 ms 8128 KB Output is correct
19 Correct 79 ms 8128 KB Output is correct
20 Correct 83 ms 8128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 676 ms 8128 KB Output is correct
2 Correct 719 ms 8128 KB Output is correct
3 Correct 746 ms 8128 KB Output is correct
4 Correct 773 ms 8128 KB Output is correct
5 Correct 673 ms 8128 KB Output is correct
6 Correct 743 ms 8128 KB Output is correct
7 Correct 783 ms 8128 KB Output is correct
8 Correct 809 ms 8128 KB Output is correct
9 Correct 716 ms 8128 KB Output is correct
10 Correct 713 ms 8128 KB Output is correct
11 Correct 789 ms 8128 KB Output is correct
12 Correct 896 ms 8128 KB Output is correct
13 Correct 786 ms 8128 KB Output is correct
14 Correct 713 ms 8128 KB Output is correct
15 Correct 696 ms 8128 KB Output is correct
16 Correct 73 ms 8128 KB Output is correct
17 Correct 89 ms 8128 KB Output is correct
18 Correct 73 ms 8128 KB Output is correct
19 Correct 79 ms 8128 KB Output is correct
20 Correct 83 ms 8128 KB Output is correct
21 Correct 1018 ms 8128 KB Output is correct
22 Correct 976 ms 8128 KB Output is correct
23 Correct 876 ms 8128 KB Output is correct
24 Correct 939 ms 8128 KB Output is correct
25 Correct 959 ms 8128 KB Output is correct
26 Correct 1176 ms 8128 KB Output is correct
27 Correct 1173 ms 8128 KB Output is correct
28 Correct 1166 ms 8128 KB Output is correct
29 Correct 1119 ms 8128 KB Output is correct
30 Correct 686 ms 8128 KB Output is correct
31 Correct 739 ms 8128 KB Output is correct
32 Correct 719 ms 8128 KB Output is correct
33 Correct 679 ms 8128 KB Output is correct
34 Correct 723 ms 8128 KB Output is correct
35 Correct 849 ms 8128 KB Output is correct
36 Correct 666 ms 8128 KB Output is correct
37 Correct 666 ms 8128 KB Output is correct
38 Correct 726 ms 8128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8128 KB Output is correct
2 Correct 13 ms 8128 KB Output is correct
3 Correct 9 ms 8128 KB Output is correct
4 Correct 13 ms 8128 KB Output is correct
5 Correct 9 ms 8128 KB Output is correct
6 Correct 13 ms 8128 KB Output is correct
7 Correct 13 ms 8128 KB Output is correct
8 Correct 13 ms 8128 KB Output is correct
9 Correct 13 ms 8128 KB Output is correct
10 Correct 13 ms 8128 KB Output is correct
11 Correct 9 ms 8128 KB Output is correct
12 Correct 6 ms 8128 KB Output is correct
13 Correct 9 ms 8128 KB Output is correct
14 Correct 9 ms 8128 KB Output is correct
15 Correct 9 ms 8128 KB Output is correct
16 Correct 6 ms 8128 KB Output is correct
17 Correct 6 ms 8128 KB Output is correct
18 Correct 6 ms 8128 KB Output is correct
19 Correct 3 ms 8128 KB Output is correct
20 Correct 6 ms 8128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 676 ms 8128 KB Output is correct
2 Correct 719 ms 8128 KB Output is correct
3 Correct 746 ms 8128 KB Output is correct
4 Correct 773 ms 8128 KB Output is correct
5 Correct 673 ms 8128 KB Output is correct
6 Correct 743 ms 8128 KB Output is correct
7 Correct 783 ms 8128 KB Output is correct
8 Correct 809 ms 8128 KB Output is correct
9 Correct 716 ms 8128 KB Output is correct
10 Correct 713 ms 8128 KB Output is correct
11 Correct 789 ms 8128 KB Output is correct
12 Correct 896 ms 8128 KB Output is correct
13 Correct 786 ms 8128 KB Output is correct
14 Correct 713 ms 8128 KB Output is correct
15 Correct 696 ms 8128 KB Output is correct
16 Correct 73 ms 8128 KB Output is correct
17 Correct 89 ms 8128 KB Output is correct
18 Correct 73 ms 8128 KB Output is correct
19 Correct 79 ms 8128 KB Output is correct
20 Correct 83 ms 8128 KB Output is correct
21 Correct 1018 ms 8128 KB Output is correct
22 Correct 976 ms 8128 KB Output is correct
23 Correct 876 ms 8128 KB Output is correct
24 Correct 939 ms 8128 KB Output is correct
25 Correct 959 ms 8128 KB Output is correct
26 Correct 1176 ms 8128 KB Output is correct
27 Correct 1173 ms 8128 KB Output is correct
28 Correct 1166 ms 8128 KB Output is correct
29 Correct 1119 ms 8128 KB Output is correct
30 Correct 686 ms 8128 KB Output is correct
31 Correct 739 ms 8128 KB Output is correct
32 Correct 719 ms 8128 KB Output is correct
33 Correct 679 ms 8128 KB Output is correct
34 Correct 723 ms 8128 KB Output is correct
35 Correct 849 ms 8128 KB Output is correct
36 Correct 666 ms 8128 KB Output is correct
37 Correct 666 ms 8128 KB Output is correct
38 Correct 726 ms 8128 KB Output is correct
39 Correct 9 ms 8128 KB Output is correct
40 Correct 13 ms 8128 KB Output is correct
41 Correct 9 ms 8128 KB Output is correct
42 Correct 13 ms 8128 KB Output is correct
43 Correct 9 ms 8128 KB Output is correct
44 Correct 13 ms 8128 KB Output is correct
45 Correct 13 ms 8128 KB Output is correct
46 Correct 13 ms 8128 KB Output is correct
47 Correct 13 ms 8128 KB Output is correct
48 Correct 13 ms 8128 KB Output is correct
49 Correct 9 ms 8128 KB Output is correct
50 Correct 6 ms 8128 KB Output is correct
51 Correct 9 ms 8128 KB Output is correct
52 Correct 9 ms 8128 KB Output is correct
53 Correct 9 ms 8128 KB Output is correct
54 Correct 6 ms 8128 KB Output is correct
55 Correct 6 ms 8128 KB Output is correct
56 Correct 6 ms 8128 KB Output is correct
57 Correct 3 ms 8128 KB Output is correct
58 Correct 6 ms 8128 KB Output is correct
59 Correct 1449 ms 8128 KB Output is correct
60 Correct 1333 ms 8128 KB Output is correct
61 Correct 1296 ms 8128 KB Output is correct
62 Correct 1323 ms 8128 KB Output is correct
63 Correct 1293 ms 8128 KB Output is correct
64 Correct 1619 ms 8128 KB Output is correct
65 Correct 1749 ms 8128 KB Output is correct
66 Correct 1576 ms 8128 KB Output is correct
67 Correct 1673 ms 8128 KB Output is correct
68 Correct 1799 ms 8128 KB Output is correct
69 Correct 1246 ms 8128 KB Output is correct
70 Correct 1163 ms 8128 KB Output is correct
71 Correct 1116 ms 8128 KB Output is correct
72 Correct 1116 ms 8128 KB Output is correct
73 Correct 1026 ms 8128 KB Output is correct
74 Correct 133 ms 8128 KB Output is correct
75 Correct 133 ms 8128 KB Output is correct
76 Correct 143 ms 8128 KB Output is correct
77 Correct 149 ms 8128 KB Output is correct
78 Correct 139 ms 8128 KB Output is correct