답안 #25849

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
25849 2017-06-24T11:49:23 Z gs14004 Boat (APIO16_boat) C++11
100 / 100
639 ms 4036 KB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <functional>
#include <numeric>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <bitset>
#include <map>
#include <set>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;

lint ipow(int x, int p){
	lint ret = 1, piv = x;
	while(p){
		if(p & 1) ret *= piv;
		piv *= piv;
		ret %= mod;
		piv %= mod;
		p >>= 1;
	}
	return ret;
}

int n, s[505], e[505];
lint inv[1005], dp[505], sum[505], dp2[505][505];
vector<int> v;

int main(){
	cin >> n;
	for(int i=1; i<=n; i++){
		cin >> s[i] >> e[i];
		e[i]++;
		v.push_back(s[i]);
		v.push_back(e[i]);
	}
	sort(v.begin(), v.end());
	v.resize(unique(v.begin(), v.end()) - v.begin());
	for(int i=1; i<=1000; i++){
		inv[i] = ipow(i, mod - 2);
	}
	dp[0] = 1;
	for(int i=1; i<v.size(); i++){
		int st = v[i-1], ed = v[i];
		vector<int> cnd;
		sum[0] = 1;
		for(int j=1; j<=n; j++){
			sum[j] = (sum[j-1] + dp[j]) % mod;
			if(s[j] <= st && ed <= e[j]){
				cnd.push_back(j);
			}
		}
		for(int i=1; i<=cnd.size() && i <= ed - st; i++){
			for(int j=i-1; j<cnd.size(); j++){
				if(i == 1){
					dp2[i][j] = sum[cnd[j] - 1] * (ed - st);
					if(j) dp2[i][j] += dp2[i][j-1];
					dp2[i][j] %= mod;
				}
				else{
					dp2[i][j] = (dp2[i-1][j-1] * inv[i] % mod) * (ed - st + 1 - i) + dp2[i][j-1];
					dp2[i][j] %= mod;
				}
			}
		}
		for(int i=1; i<=cnd.size() && i <= ed - st; i++){
			for(int j=i-1; j<cnd.size(); j++){
				int cnt = dp2[i][j] - (j ? dp2[i][j-1] : 0) + mod;
				cnt %= mod;
				dp[cnd[j]] += cnt;
				dp[cnd[j]] %= mod;
			}
		}
	}
	int ret= 0;
	for(int i=1; i<=n; i++){
		ret += dp[i];
		ret %= mod;
	}
	cout << ret;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:56:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=1; i<v.size(); i++){
                ^
boat.cpp:66:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=1; i<=cnd.size() && i <= ed - st; i++){
                 ^
boat.cpp:67:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j=i-1; j<cnd.size(); j++){
                    ^
boat.cpp:79:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=1; i<=cnd.size() && i <= ed - st; i++){
                 ^
boat.cpp:80:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j=i-1; j<cnd.size(); j++){
                    ^
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4036 KB Output is correct
2 Correct 3 ms 4036 KB Output is correct
3 Correct 3 ms 4036 KB Output is correct
4 Correct 6 ms 4036 KB Output is correct
5 Correct 6 ms 4036 KB Output is correct
6 Correct 3 ms 4036 KB Output is correct
7 Correct 3 ms 4036 KB Output is correct
8 Correct 3 ms 4036 KB Output is correct
9 Correct 3 ms 4036 KB Output is correct
10 Correct 3 ms 4036 KB Output is correct
11 Correct 3 ms 4036 KB Output is correct
12 Correct 3 ms 4036 KB Output is correct
13 Correct 3 ms 4036 KB Output is correct
14 Correct 3 ms 4036 KB Output is correct
15 Correct 3 ms 4036 KB Output is correct
16 Correct 0 ms 4036 KB Output is correct
17 Correct 0 ms 4036 KB Output is correct
18 Correct 0 ms 4036 KB Output is correct
19 Correct 0 ms 4036 KB Output is correct
20 Correct 0 ms 4036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4036 KB Output is correct
2 Correct 3 ms 4036 KB Output is correct
3 Correct 3 ms 4036 KB Output is correct
4 Correct 6 ms 4036 KB Output is correct
5 Correct 6 ms 4036 KB Output is correct
6 Correct 3 ms 4036 KB Output is correct
7 Correct 3 ms 4036 KB Output is correct
8 Correct 3 ms 4036 KB Output is correct
9 Correct 3 ms 4036 KB Output is correct
10 Correct 3 ms 4036 KB Output is correct
11 Correct 3 ms 4036 KB Output is correct
12 Correct 3 ms 4036 KB Output is correct
13 Correct 3 ms 4036 KB Output is correct
14 Correct 3 ms 4036 KB Output is correct
15 Correct 3 ms 4036 KB Output is correct
16 Correct 0 ms 4036 KB Output is correct
17 Correct 0 ms 4036 KB Output is correct
18 Correct 0 ms 4036 KB Output is correct
19 Correct 0 ms 4036 KB Output is correct
20 Correct 0 ms 4036 KB Output is correct
21 Correct 16 ms 4036 KB Output is correct
22 Correct 16 ms 4036 KB Output is correct
23 Correct 19 ms 4036 KB Output is correct
24 Correct 16 ms 4036 KB Output is correct
25 Correct 16 ms 4036 KB Output is correct
26 Correct 16 ms 4036 KB Output is correct
27 Correct 19 ms 4036 KB Output is correct
28 Correct 19 ms 4036 KB Output is correct
29 Correct 16 ms 4036 KB Output is correct
30 Correct 3 ms 4036 KB Output is correct
31 Correct 3 ms 4036 KB Output is correct
32 Correct 3 ms 4036 KB Output is correct
33 Correct 3 ms 4036 KB Output is correct
34 Correct 3 ms 4036 KB Output is correct
35 Correct 3 ms 4036 KB Output is correct
36 Correct 3 ms 4036 KB Output is correct
37 Correct 3 ms 4036 KB Output is correct
38 Correct 3 ms 4036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4036 KB Output is correct
2 Correct 3 ms 4036 KB Output is correct
3 Correct 3 ms 4036 KB Output is correct
4 Correct 0 ms 4036 KB Output is correct
5 Correct 3 ms 4036 KB Output is correct
6 Correct 6 ms 4036 KB Output is correct
7 Correct 3 ms 4036 KB Output is correct
8 Correct 6 ms 4036 KB Output is correct
9 Correct 6 ms 4036 KB Output is correct
10 Correct 6 ms 4036 KB Output is correct
11 Correct 3 ms 4036 KB Output is correct
12 Correct 3 ms 4036 KB Output is correct
13 Correct 3 ms 4036 KB Output is correct
14 Correct 3 ms 4036 KB Output is correct
15 Correct 3 ms 4036 KB Output is correct
16 Correct 0 ms 4036 KB Output is correct
17 Correct 0 ms 4036 KB Output is correct
18 Correct 0 ms 4036 KB Output is correct
19 Correct 0 ms 4036 KB Output is correct
20 Correct 0 ms 4036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4036 KB Output is correct
2 Correct 3 ms 4036 KB Output is correct
3 Correct 3 ms 4036 KB Output is correct
4 Correct 6 ms 4036 KB Output is correct
5 Correct 6 ms 4036 KB Output is correct
6 Correct 3 ms 4036 KB Output is correct
7 Correct 3 ms 4036 KB Output is correct
8 Correct 3 ms 4036 KB Output is correct
9 Correct 3 ms 4036 KB Output is correct
10 Correct 3 ms 4036 KB Output is correct
11 Correct 3 ms 4036 KB Output is correct
12 Correct 3 ms 4036 KB Output is correct
13 Correct 3 ms 4036 KB Output is correct
14 Correct 3 ms 4036 KB Output is correct
15 Correct 3 ms 4036 KB Output is correct
16 Correct 0 ms 4036 KB Output is correct
17 Correct 0 ms 4036 KB Output is correct
18 Correct 0 ms 4036 KB Output is correct
19 Correct 0 ms 4036 KB Output is correct
20 Correct 0 ms 4036 KB Output is correct
21 Correct 16 ms 4036 KB Output is correct
22 Correct 16 ms 4036 KB Output is correct
23 Correct 19 ms 4036 KB Output is correct
24 Correct 16 ms 4036 KB Output is correct
25 Correct 16 ms 4036 KB Output is correct
26 Correct 16 ms 4036 KB Output is correct
27 Correct 19 ms 4036 KB Output is correct
28 Correct 19 ms 4036 KB Output is correct
29 Correct 16 ms 4036 KB Output is correct
30 Correct 3 ms 4036 KB Output is correct
31 Correct 3 ms 4036 KB Output is correct
32 Correct 3 ms 4036 KB Output is correct
33 Correct 3 ms 4036 KB Output is correct
34 Correct 3 ms 4036 KB Output is correct
35 Correct 3 ms 4036 KB Output is correct
36 Correct 3 ms 4036 KB Output is correct
37 Correct 3 ms 4036 KB Output is correct
38 Correct 3 ms 4036 KB Output is correct
39 Correct 3 ms 4036 KB Output is correct
40 Correct 3 ms 4036 KB Output is correct
41 Correct 3 ms 4036 KB Output is correct
42 Correct 0 ms 4036 KB Output is correct
43 Correct 3 ms 4036 KB Output is correct
44 Correct 6 ms 4036 KB Output is correct
45 Correct 3 ms 4036 KB Output is correct
46 Correct 6 ms 4036 KB Output is correct
47 Correct 6 ms 4036 KB Output is correct
48 Correct 6 ms 4036 KB Output is correct
49 Correct 3 ms 4036 KB Output is correct
50 Correct 3 ms 4036 KB Output is correct
51 Correct 3 ms 4036 KB Output is correct
52 Correct 3 ms 4036 KB Output is correct
53 Correct 3 ms 4036 KB Output is correct
54 Correct 0 ms 4036 KB Output is correct
55 Correct 0 ms 4036 KB Output is correct
56 Correct 0 ms 4036 KB Output is correct
57 Correct 0 ms 4036 KB Output is correct
58 Correct 0 ms 4036 KB Output is correct
59 Correct 266 ms 4036 KB Output is correct
60 Correct 226 ms 4036 KB Output is correct
61 Correct 216 ms 4036 KB Output is correct
62 Correct 263 ms 4036 KB Output is correct
63 Correct 256 ms 4036 KB Output is correct
64 Correct 576 ms 4036 KB Output is correct
65 Correct 586 ms 4036 KB Output is correct
66 Correct 639 ms 4036 KB Output is correct
67 Correct 609 ms 4036 KB Output is correct
68 Correct 579 ms 4036 KB Output is correct
69 Correct 226 ms 4036 KB Output is correct
70 Correct 213 ms 4036 KB Output is correct
71 Correct 219 ms 4036 KB Output is correct
72 Correct 236 ms 4036 KB Output is correct
73 Correct 263 ms 4036 KB Output is correct
74 Correct 26 ms 4036 KB Output is correct
75 Correct 26 ms 4036 KB Output is correct
76 Correct 23 ms 4036 KB Output is correct
77 Correct 26 ms 4036 KB Output is correct
78 Correct 29 ms 4036 KB Output is correct