답안 #45674

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
45674 2018-04-16T02:19:56 Z gnoor Boat (APIO16_boat) C++17
100 / 100
1935 ms 10960 KB
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

map<int,int> mp;
int a[600];
int b[600];
int mod=1000000007;
int dec[1010];

long long dp[600][1010];
long long q[1010][600];

long long inv[1010];

long long poww(long long x,int d) {
	if (d==0) return 1;
	if (d==1) return x;
	long long tmp=poww(x,d/2);
	tmp=tmp*tmp;
	tmp%=mod;
	if (d%2) return (tmp*x)%mod;
	return tmp;
}

int main () {
	int n;
	scanf("%d",&n);
	for (int i=0;i<n;i++) {
		scanf("%d%d",&a[i],&b[i]);
		mp[a[i]-1];
		mp[b[i]];
	}
	int i=1;
	for (auto &ii:mp) {
		dec[i]=ii.first;
		ii.second=i++;
	}
	for (int i=0;i<n;i++) {
		a[i]=mp[a[i]-1];
		b[i]=mp[b[i]];
	}
	int nn=mp.size();

	for (int i=1;i<=n;i++) {
		inv[i]=poww(i,mod-2);
	}

	vector<int> rng;
	for (int i=0;i<n;i++) {
		for (int k=a[i]+1;k<=b[i];k++) {
			rng.push_back(dec[k]-dec[k-1]);
		}
	}
	rng.push_back(0);
	sort(rng.begin(),rng.end());
	rng.erase(unique(rng.begin(),rng.end()),rng.end());
	int val;	
	//printf("--- %d\n",rng.size());
	for (int k=1;k<(int)rng.size();k++) {
		val=rng[k];	
		q[k][0]=1;
		for (int j=1;j<=n;j++) {
			q[k][j]=q[k][j-1]*(val+j-1);
			q[k][j]%=mod;
			q[k][j]*=inv[j];
			q[k][j]%=mod;
			//printf("%lld ",q[k][j]);
		}
		//printf("\n");
	}	
	
	int kk;
	for (int i=0;i<n;i++) {
		//printf("** %d %d\n",a[i],b[i]);
		for (int k=a[i]+1;k<=b[i];k++) {
			int cnt=1;
			kk=lower_bound(rng.begin(),rng.end(),dec[k]-dec[k-1])-rng.begin();
			for (int j=i-1;j>=0;j--) {
				//printf("** %d %d %d %lld\n",i,j,k,dp[j][k-1]);
				dp[i][k]+=dp[j][k-1]*(q[kk][cnt]);
				//dp[i][k]+=dp[j][k-1]*(dec[k]-dec[k-1]);
				dp[i][k]%=mod;
				if (k>a[j]&&k<=b[j]) cnt++;
			}
			dp[i][k]+=q[kk][cnt];
			dp[i][k]+=dp[i][k-1];
			dp[i][k]%=mod;			
		}
		//for (int k=a[i]+1;k<=b[i];k++) {
			//dp[i][k]+=(dec[k]-dec[k-1]);
			//dp[i][k]+=dp[i][k-1];
			//dp[i][k]%=mod;
		//}
		for (int k=b[i]+1;k<=nn;k++) {
			dp[i][k]+=dp[i][k-1];
			dp[i][k]%=mod;
		}
		//for (int k=1;k<=nn;k++) {
			//printf("%lld ",dp[i][k]);
		//}
		//printf("\n");
	}
	long long ans=0;
	for (int i=0;i<n;i++) {
		ans+=dp[i][nn];
		ans%=mod;
	}
	ans+=mod;
	ans%=mod;
	printf("%lld\n",ans);
	return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:31:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
boat.cpp:33:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&a[i],&b[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 3836 KB Output is correct
2 Correct 18 ms 3940 KB Output is correct
3 Correct 18 ms 4144 KB Output is correct
4 Correct 16 ms 4144 KB Output is correct
5 Correct 18 ms 4144 KB Output is correct
6 Correct 16 ms 4144 KB Output is correct
7 Correct 16 ms 4168 KB Output is correct
8 Correct 15 ms 4168 KB Output is correct
9 Correct 16 ms 4168 KB Output is correct
10 Correct 17 ms 4168 KB Output is correct
11 Correct 17 ms 4168 KB Output is correct
12 Correct 16 ms 4168 KB Output is correct
13 Correct 16 ms 4168 KB Output is correct
14 Correct 15 ms 4168 KB Output is correct
15 Correct 16 ms 4168 KB Output is correct
16 Correct 11 ms 4168 KB Output is correct
17 Correct 9 ms 4168 KB Output is correct
18 Correct 9 ms 4168 KB Output is correct
19 Correct 10 ms 4168 KB Output is correct
20 Correct 10 ms 4168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 3836 KB Output is correct
2 Correct 18 ms 3940 KB Output is correct
3 Correct 18 ms 4144 KB Output is correct
4 Correct 16 ms 4144 KB Output is correct
5 Correct 18 ms 4144 KB Output is correct
6 Correct 16 ms 4144 KB Output is correct
7 Correct 16 ms 4168 KB Output is correct
8 Correct 15 ms 4168 KB Output is correct
9 Correct 16 ms 4168 KB Output is correct
10 Correct 17 ms 4168 KB Output is correct
11 Correct 17 ms 4168 KB Output is correct
12 Correct 16 ms 4168 KB Output is correct
13 Correct 16 ms 4168 KB Output is correct
14 Correct 15 ms 4168 KB Output is correct
15 Correct 16 ms 4168 KB Output is correct
16 Correct 11 ms 4168 KB Output is correct
17 Correct 9 ms 4168 KB Output is correct
18 Correct 9 ms 4168 KB Output is correct
19 Correct 10 ms 4168 KB Output is correct
20 Correct 10 ms 4168 KB Output is correct
21 Correct 1200 ms 5424 KB Output is correct
22 Correct 1125 ms 5424 KB Output is correct
23 Correct 1211 ms 5424 KB Output is correct
24 Correct 1212 ms 5572 KB Output is correct
25 Correct 1211 ms 5572 KB Output is correct
26 Correct 1589 ms 6020 KB Output is correct
27 Correct 1376 ms 6020 KB Output is correct
28 Correct 1394 ms 6020 KB Output is correct
29 Correct 1303 ms 6020 KB Output is correct
30 Correct 33 ms 6452 KB Output is correct
31 Correct 33 ms 6480 KB Output is correct
32 Correct 35 ms 6572 KB Output is correct
33 Correct 33 ms 6600 KB Output is correct
34 Correct 32 ms 6628 KB Output is correct
35 Correct 38 ms 6628 KB Output is correct
36 Correct 35 ms 6628 KB Output is correct
37 Correct 34 ms 6628 KB Output is correct
38 Correct 35 ms 6628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 6628 KB Output is correct
2 Correct 11 ms 6628 KB Output is correct
3 Correct 11 ms 6628 KB Output is correct
4 Correct 12 ms 6628 KB Output is correct
5 Correct 12 ms 6628 KB Output is correct
6 Correct 15 ms 6628 KB Output is correct
7 Correct 16 ms 6628 KB Output is correct
8 Correct 18 ms 6628 KB Output is correct
9 Correct 16 ms 6628 KB Output is correct
10 Correct 17 ms 6628 KB Output is correct
11 Correct 12 ms 6628 KB Output is correct
12 Correct 10 ms 6628 KB Output is correct
13 Correct 10 ms 6628 KB Output is correct
14 Correct 11 ms 6628 KB Output is correct
15 Correct 12 ms 6628 KB Output is correct
16 Correct 7 ms 6628 KB Output is correct
17 Correct 8 ms 6628 KB Output is correct
18 Correct 7 ms 6628 KB Output is correct
19 Correct 7 ms 6628 KB Output is correct
20 Correct 7 ms 6628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 3836 KB Output is correct
2 Correct 18 ms 3940 KB Output is correct
3 Correct 18 ms 4144 KB Output is correct
4 Correct 16 ms 4144 KB Output is correct
5 Correct 18 ms 4144 KB Output is correct
6 Correct 16 ms 4144 KB Output is correct
7 Correct 16 ms 4168 KB Output is correct
8 Correct 15 ms 4168 KB Output is correct
9 Correct 16 ms 4168 KB Output is correct
10 Correct 17 ms 4168 KB Output is correct
11 Correct 17 ms 4168 KB Output is correct
12 Correct 16 ms 4168 KB Output is correct
13 Correct 16 ms 4168 KB Output is correct
14 Correct 15 ms 4168 KB Output is correct
15 Correct 16 ms 4168 KB Output is correct
16 Correct 11 ms 4168 KB Output is correct
17 Correct 9 ms 4168 KB Output is correct
18 Correct 9 ms 4168 KB Output is correct
19 Correct 10 ms 4168 KB Output is correct
20 Correct 10 ms 4168 KB Output is correct
21 Correct 1200 ms 5424 KB Output is correct
22 Correct 1125 ms 5424 KB Output is correct
23 Correct 1211 ms 5424 KB Output is correct
24 Correct 1212 ms 5572 KB Output is correct
25 Correct 1211 ms 5572 KB Output is correct
26 Correct 1589 ms 6020 KB Output is correct
27 Correct 1376 ms 6020 KB Output is correct
28 Correct 1394 ms 6020 KB Output is correct
29 Correct 1303 ms 6020 KB Output is correct
30 Correct 33 ms 6452 KB Output is correct
31 Correct 33 ms 6480 KB Output is correct
32 Correct 35 ms 6572 KB Output is correct
33 Correct 33 ms 6600 KB Output is correct
34 Correct 32 ms 6628 KB Output is correct
35 Correct 38 ms 6628 KB Output is correct
36 Correct 35 ms 6628 KB Output is correct
37 Correct 34 ms 6628 KB Output is correct
38 Correct 35 ms 6628 KB Output is correct
39 Correct 11 ms 6628 KB Output is correct
40 Correct 11 ms 6628 KB Output is correct
41 Correct 11 ms 6628 KB Output is correct
42 Correct 12 ms 6628 KB Output is correct
43 Correct 12 ms 6628 KB Output is correct
44 Correct 15 ms 6628 KB Output is correct
45 Correct 16 ms 6628 KB Output is correct
46 Correct 18 ms 6628 KB Output is correct
47 Correct 16 ms 6628 KB Output is correct
48 Correct 17 ms 6628 KB Output is correct
49 Correct 12 ms 6628 KB Output is correct
50 Correct 10 ms 6628 KB Output is correct
51 Correct 10 ms 6628 KB Output is correct
52 Correct 11 ms 6628 KB Output is correct
53 Correct 12 ms 6628 KB Output is correct
54 Correct 7 ms 6628 KB Output is correct
55 Correct 8 ms 6628 KB Output is correct
56 Correct 7 ms 6628 KB Output is correct
57 Correct 7 ms 6628 KB Output is correct
58 Correct 7 ms 6628 KB Output is correct
59 Correct 1410 ms 10448 KB Output is correct
60 Correct 1493 ms 10448 KB Output is correct
61 Correct 1242 ms 10448 KB Output is correct
62 Correct 1364 ms 10448 KB Output is correct
63 Correct 1338 ms 10448 KB Output is correct
64 Correct 1768 ms 10956 KB Output is correct
65 Correct 1935 ms 10960 KB Output is correct
66 Correct 1856 ms 10960 KB Output is correct
67 Correct 1923 ms 10960 KB Output is correct
68 Correct 1927 ms 10960 KB Output is correct
69 Correct 946 ms 10960 KB Output is correct
70 Correct 985 ms 10960 KB Output is correct
71 Correct 893 ms 10960 KB Output is correct
72 Correct 989 ms 10960 KB Output is correct
73 Correct 889 ms 10960 KB Output is correct
74 Correct 188 ms 10960 KB Output is correct
75 Correct 179 ms 10960 KB Output is correct
76 Correct 188 ms 10960 KB Output is correct
77 Correct 189 ms 10960 KB Output is correct
78 Correct 189 ms 10960 KB Output is correct