Submission #734529

# Submission time Handle Problem Language Result Execution time Memory
734529 2023-05-02T15:15:52 Z vjudge1 Boat (APIO16_boat) C++14
100 / 100
590 ms 2472 KB
#include<stdio.h>
#include<algorithm>
#define N 509
#define M 1009
#define mod 1000000007
using namespace std;
inline char nc()
{
	static char buf[99999],*l,*r;
	return l==r&&(r=(l=buf)+fread(buf,1,99999,stdin),l==r)?EOF:*l++;
}
inline void read(int&x)
{
	char c=nc();for(;c<'0'||'9'<c;c=nc());
	for(x=0;'0'<=c&&c<='9';x=(x<<3)+(x<<1)+(c^48),c=nc());
}
int n,m,a[N],b[N],lsh[M],f[N][M],inv[N],ans;
inline long long ksm(long long a,int b)
{
	long long ans=1;
	for(;b;b>>=1,a*=a,a%=mod)if(b&1)ans*=a,ans%=mod;
	return ans;
}
main()
{
	read(n);
	for(int i=1;i<=n;inv[i]=ksm(i,mod-2),++i)
		read(a[i]),read(b[i]),lsh[m++]=a[i],lsh[m++]=b[i]+1;
	lsh[m++]=0;lsh[m++]=1000000001;
	sort(lsh,lsh+m);m=unique(lsh,lsh+m)-lsh;--m;
	for(int i=0;i<m;f[0][i++]=1);
	for(int i=1;i<=n;++i)
	{
		for(int l=lower_bound(lsh,lsh+m,a[i])-lsh,r=upper_bound(lsh,lsh+m,b[i])-lsh
			;l<r;++l)
		{
			for(int j=i-1,k=lsh[l+1]-lsh[l],cnt=1;j>=0;--j)
			{
				f[i][l]=(f[i][l]+(long long)(k)*f[j][l-1])%mod;
				if(a[j]<=lsh[l]&&lsh[l]<=b[j])++cnt,
					k=k*(long long)(lsh[l+1]-lsh[l]+cnt-1)%mod*inv[cnt]%mod;
			}
		}
		for(int j=1;j<m;++j)f[i][j]+=f[i][j-1]-mod,f[i][j]>>31&&(f[i][j]+=mod);
		ans+=f[i][m-1]-mod,ans>>31&&(ans+=mod);
	}
	printf("%d",ans);
}

Compilation message

boat.cpp:24:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   24 | main()
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2260 KB Output is correct
2 Correct 5 ms 2260 KB Output is correct
3 Correct 5 ms 2216 KB Output is correct
4 Correct 5 ms 2260 KB Output is correct
5 Correct 4 ms 2260 KB Output is correct
6 Correct 5 ms 2236 KB Output is correct
7 Correct 5 ms 2260 KB Output is correct
8 Correct 5 ms 2260 KB Output is correct
9 Correct 5 ms 2260 KB Output is correct
10 Correct 5 ms 2248 KB Output is correct
11 Correct 4 ms 2260 KB Output is correct
12 Correct 5 ms 2260 KB Output is correct
13 Correct 5 ms 2228 KB Output is correct
14 Correct 5 ms 2216 KB Output is correct
15 Correct 4 ms 2260 KB Output is correct
16 Correct 3 ms 2228 KB Output is correct
17 Correct 3 ms 2260 KB Output is correct
18 Correct 3 ms 2260 KB Output is correct
19 Correct 3 ms 2260 KB Output is correct
20 Correct 3 ms 2228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2260 KB Output is correct
2 Correct 5 ms 2260 KB Output is correct
3 Correct 5 ms 2216 KB Output is correct
4 Correct 5 ms 2260 KB Output is correct
5 Correct 4 ms 2260 KB Output is correct
6 Correct 5 ms 2236 KB Output is correct
7 Correct 5 ms 2260 KB Output is correct
8 Correct 5 ms 2260 KB Output is correct
9 Correct 5 ms 2260 KB Output is correct
10 Correct 5 ms 2248 KB Output is correct
11 Correct 4 ms 2260 KB Output is correct
12 Correct 5 ms 2260 KB Output is correct
13 Correct 5 ms 2228 KB Output is correct
14 Correct 5 ms 2216 KB Output is correct
15 Correct 4 ms 2260 KB Output is correct
16 Correct 3 ms 2228 KB Output is correct
17 Correct 3 ms 2260 KB Output is correct
18 Correct 3 ms 2260 KB Output is correct
19 Correct 3 ms 2260 KB Output is correct
20 Correct 3 ms 2228 KB Output is correct
21 Correct 256 ms 2252 KB Output is correct
22 Correct 259 ms 2168 KB Output is correct
23 Correct 218 ms 2276 KB Output is correct
24 Correct 257 ms 2264 KB Output is correct
25 Correct 246 ms 2208 KB Output is correct
26 Correct 516 ms 2212 KB Output is correct
27 Correct 536 ms 2216 KB Output is correct
28 Correct 501 ms 2244 KB Output is correct
29 Correct 486 ms 2264 KB Output is correct
30 Correct 5 ms 2260 KB Output is correct
31 Correct 6 ms 2260 KB Output is correct
32 Correct 6 ms 2260 KB Output is correct
33 Correct 5 ms 2204 KB Output is correct
34 Correct 6 ms 2300 KB Output is correct
35 Correct 7 ms 2224 KB Output is correct
36 Correct 6 ms 2240 KB Output is correct
37 Correct 6 ms 2260 KB Output is correct
38 Correct 6 ms 2260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 596 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 3 ms 596 KB Output is correct
4 Correct 3 ms 684 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 6 ms 616 KB Output is correct
7 Correct 6 ms 680 KB Output is correct
8 Correct 5 ms 596 KB Output is correct
9 Correct 6 ms 692 KB Output is correct
10 Correct 6 ms 648 KB Output is correct
11 Correct 3 ms 684 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 3 ms 596 KB Output is correct
14 Correct 3 ms 596 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 2 ms 596 KB Output is correct
20 Correct 2 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2260 KB Output is correct
2 Correct 5 ms 2260 KB Output is correct
3 Correct 5 ms 2216 KB Output is correct
4 Correct 5 ms 2260 KB Output is correct
5 Correct 4 ms 2260 KB Output is correct
6 Correct 5 ms 2236 KB Output is correct
7 Correct 5 ms 2260 KB Output is correct
8 Correct 5 ms 2260 KB Output is correct
9 Correct 5 ms 2260 KB Output is correct
10 Correct 5 ms 2248 KB Output is correct
11 Correct 4 ms 2260 KB Output is correct
12 Correct 5 ms 2260 KB Output is correct
13 Correct 5 ms 2228 KB Output is correct
14 Correct 5 ms 2216 KB Output is correct
15 Correct 4 ms 2260 KB Output is correct
16 Correct 3 ms 2228 KB Output is correct
17 Correct 3 ms 2260 KB Output is correct
18 Correct 3 ms 2260 KB Output is correct
19 Correct 3 ms 2260 KB Output is correct
20 Correct 3 ms 2228 KB Output is correct
21 Correct 256 ms 2252 KB Output is correct
22 Correct 259 ms 2168 KB Output is correct
23 Correct 218 ms 2276 KB Output is correct
24 Correct 257 ms 2264 KB Output is correct
25 Correct 246 ms 2208 KB Output is correct
26 Correct 516 ms 2212 KB Output is correct
27 Correct 536 ms 2216 KB Output is correct
28 Correct 501 ms 2244 KB Output is correct
29 Correct 486 ms 2264 KB Output is correct
30 Correct 5 ms 2260 KB Output is correct
31 Correct 6 ms 2260 KB Output is correct
32 Correct 6 ms 2260 KB Output is correct
33 Correct 5 ms 2204 KB Output is correct
34 Correct 6 ms 2300 KB Output is correct
35 Correct 7 ms 2224 KB Output is correct
36 Correct 6 ms 2240 KB Output is correct
37 Correct 6 ms 2260 KB Output is correct
38 Correct 6 ms 2260 KB Output is correct
39 Correct 3 ms 596 KB Output is correct
40 Correct 3 ms 596 KB Output is correct
41 Correct 3 ms 596 KB Output is correct
42 Correct 3 ms 684 KB Output is correct
43 Correct 3 ms 596 KB Output is correct
44 Correct 6 ms 616 KB Output is correct
45 Correct 6 ms 680 KB Output is correct
46 Correct 5 ms 596 KB Output is correct
47 Correct 6 ms 692 KB Output is correct
48 Correct 6 ms 648 KB Output is correct
49 Correct 3 ms 684 KB Output is correct
50 Correct 2 ms 596 KB Output is correct
51 Correct 3 ms 596 KB Output is correct
52 Correct 3 ms 596 KB Output is correct
53 Correct 3 ms 596 KB Output is correct
54 Correct 2 ms 596 KB Output is correct
55 Correct 2 ms 596 KB Output is correct
56 Correct 2 ms 596 KB Output is correct
57 Correct 2 ms 596 KB Output is correct
58 Correct 2 ms 596 KB Output is correct
59 Correct 283 ms 2472 KB Output is correct
60 Correct 348 ms 2256 KB Output is correct
61 Correct 235 ms 2244 KB Output is correct
62 Correct 279 ms 2228 KB Output is correct
63 Correct 263 ms 2456 KB Output is correct
64 Correct 590 ms 2244 KB Output is correct
65 Correct 566 ms 2208 KB Output is correct
66 Correct 562 ms 2276 KB Output is correct
67 Correct 551 ms 2168 KB Output is correct
68 Correct 574 ms 2328 KB Output is correct
69 Correct 208 ms 2256 KB Output is correct
70 Correct 220 ms 2244 KB Output is correct
71 Correct 227 ms 2188 KB Output is correct
72 Correct 236 ms 2268 KB Output is correct
73 Correct 244 ms 2176 KB Output is correct
74 Correct 61 ms 2176 KB Output is correct
75 Correct 55 ms 2180 KB Output is correct
76 Correct 56 ms 2168 KB Output is correct
77 Correct 53 ms 2224 KB Output is correct
78 Correct 55 ms 2260 KB Output is correct