Submission #20366

# Submission time Handle Problem Language Result Execution time Memory
20366 2017-02-07T08:43:43 Z 초음속철도 (OJUZ11_rail) C++
45 / 100
629 ms 253388 KB
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
#define MOD (ll)(1e9+7)

int N,M;
const int MAX_M = 5010;

ll dp[MAX_M][MAX_M];
ll dp2[400010];

struct pt{
	int s,e;
	pt(){}
	pt(int s_,int e_):s(s_),e(e_){}
	bool operator<(const pt& r)const{
		return s!=r.s?s<r.s:e<r.e;
	}
}a[MAX_M];

ll pw(ll x,ll y){
	ll ret=1;
	while(y){
		if(y&1)ret=(ret*x)%MOD;
		x=(x*x)%MOD;
		y>>=1;
	}
	return ret;
}

ll f(int x,int lim){
	if(x>M)return a[lim].e==N;
	if(a[lim].e<a[x].s)return 0;
	ll& ret=dp[x][lim];
	if(~ret)return ret;
	ret=(f(x+1,lim)+f(x+1,a[lim].e<a[x].e?x:lim))%MOD;

	return ret;
}

ll f2(int x){
	if(x==N)return 1;
	ll& ret=dp2[x];
	if(~ret)return ret;
	ret=0;
	int L=lower_bound(a+1,a+M+1,pt(x,0))-a;
	int R=lower_bound(a+1,a+M+1,pt(x+1,0))-a;
	for(int i=L;i<R;i++){
		ret+=f2(a[i].e);
		ret%=MOD;
	}
	return ret;
}

int cmp[400010],sz;
int main(){

	memset(dp,-1,sizeof(dp));
	memset(dp2,-1,sizeof(dp2));

	scanf("%d%d",&N,&M);

	a[0]=pt{1,1};
	cmp[sz++]=1;cmp[sz++]=N;
	for(int i=1,x,y;i<=M;i++){
		scanf("%d%d",&x,&y);
		a[i]=pt(x,y);
		cmp[sz++]=x;
		cmp[sz++]=y;
	}

	sort(cmp,cmp+sz);
	sz=unique(cmp,cmp+sz)-cmp;
	for(int i=0;i<=M;i++){
		a[i].s=lower_bound(cmp,cmp+sz,a[i].s)-cmp;
		a[i].e=lower_bound(cmp,cmp+sz,a[i].e)-cmp;
	}
	N=lower_bound(cmp,cmp+sz,N)-cmp;

	sort(a+1,a+M+1);
	
	if(M>=MAX_M){
		printf("%lld\n",f2(0));
	}

	printf("%lld\n",f(1,0));

	return 0;
}

Compilation message

rail.cpp: In function 'int main()':
rail.cpp:65:9: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
  a[0]=pt{1,1};
         ^
rail.cpp:63:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&N,&M);
                     ^
rail.cpp:68:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&x,&y);
                      ^
# Verdict Execution time Memory Grader output
1 Correct 125 ms 199812 KB Output is correct
2 Correct 127 ms 199864 KB Output is correct
3 Correct 127 ms 199892 KB Output is correct
4 Correct 128 ms 199892 KB Output is correct
5 Correct 128 ms 199892 KB Output is correct
6 Correct 127 ms 199892 KB Output is correct
7 Correct 127 ms 199892 KB Output is correct
8 Correct 126 ms 199892 KB Output is correct
9 Correct 125 ms 199892 KB Output is correct
10 Correct 128 ms 199896 KB Output is correct
11 Correct 126 ms 199948 KB Output is correct
12 Correct 125 ms 199948 KB Output is correct
13 Correct 125 ms 199948 KB Output is correct
14 Correct 135 ms 199952 KB Output is correct
15 Correct 133 ms 199952 KB Output is correct
16 Correct 138 ms 199952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 125 ms 199812 KB Output is correct
2 Correct 127 ms 199864 KB Output is correct
3 Correct 127 ms 199892 KB Output is correct
4 Correct 128 ms 199892 KB Output is correct
5 Correct 128 ms 199892 KB Output is correct
6 Correct 127 ms 199892 KB Output is correct
7 Correct 127 ms 199892 KB Output is correct
8 Correct 126 ms 199892 KB Output is correct
9 Correct 125 ms 199892 KB Output is correct
10 Correct 128 ms 199896 KB Output is correct
11 Correct 126 ms 199948 KB Output is correct
12 Correct 125 ms 199948 KB Output is correct
13 Correct 125 ms 199948 KB Output is correct
14 Correct 135 ms 199952 KB Output is correct
15 Correct 133 ms 199952 KB Output is correct
16 Correct 138 ms 199952 KB Output is correct
17 Correct 135 ms 199952 KB Output is correct
18 Correct 129 ms 199952 KB Output is correct
19 Correct 127 ms 199952 KB Output is correct
20 Correct 127 ms 199952 KB Output is correct
21 Correct 132 ms 199952 KB Output is correct
22 Correct 127 ms 199952 KB Output is correct
23 Correct 127 ms 199952 KB Output is correct
24 Correct 127 ms 199952 KB Output is correct
25 Correct 132 ms 199952 KB Output is correct
26 Correct 126 ms 199952 KB Output is correct
27 Correct 126 ms 199952 KB Output is correct
28 Correct 129 ms 199952 KB Output is correct
29 Correct 144 ms 199952 KB Output is correct
30 Correct 126 ms 199952 KB Output is correct
31 Correct 128 ms 199952 KB Output is correct
32 Correct 129 ms 199952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 128 ms 199952 KB Output is correct
2 Correct 129 ms 199956 KB Output is correct
3 Correct 126 ms 199956 KB Output is correct
4 Correct 502 ms 200464 KB Output is correct
5 Incorrect 278 ms 201996 KB Output isn't correct
6 Incorrect 317 ms 201996 KB Output isn't correct
7 Incorrect 298 ms 201996 KB Output isn't correct
8 Correct 127 ms 201996 KB Output is correct
9 Incorrect 297 ms 201996 KB Output isn't correct
10 Incorrect 311 ms 201996 KB Output isn't correct
11 Runtime error 232 ms 252088 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Incorrect 332 ms 252808 KB Output isn't correct
13 Incorrect 306 ms 252808 KB Output isn't correct
14 Runtime error 246 ms 253272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Runtime error 259 ms 253272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Incorrect 326 ms 253272 KB Output isn't correct
17 Incorrect 331 ms 253272 KB Output isn't correct
18 Incorrect 318 ms 253272 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 125 ms 199812 KB Output is correct
2 Correct 127 ms 199864 KB Output is correct
3 Correct 127 ms 199892 KB Output is correct
4 Correct 128 ms 199892 KB Output is correct
5 Correct 128 ms 199892 KB Output is correct
6 Correct 127 ms 199892 KB Output is correct
7 Correct 127 ms 199892 KB Output is correct
8 Correct 126 ms 199892 KB Output is correct
9 Correct 125 ms 199892 KB Output is correct
10 Correct 128 ms 199896 KB Output is correct
11 Correct 126 ms 199948 KB Output is correct
12 Correct 125 ms 199948 KB Output is correct
13 Correct 125 ms 199948 KB Output is correct
14 Correct 135 ms 199952 KB Output is correct
15 Correct 133 ms 199952 KB Output is correct
16 Correct 138 ms 199952 KB Output is correct
17 Correct 135 ms 199952 KB Output is correct
18 Correct 129 ms 199952 KB Output is correct
19 Correct 127 ms 199952 KB Output is correct
20 Correct 127 ms 199952 KB Output is correct
21 Correct 132 ms 199952 KB Output is correct
22 Correct 127 ms 199952 KB Output is correct
23 Correct 127 ms 199952 KB Output is correct
24 Correct 127 ms 199952 KB Output is correct
25 Correct 132 ms 199952 KB Output is correct
26 Correct 126 ms 199952 KB Output is correct
27 Correct 126 ms 199952 KB Output is correct
28 Correct 129 ms 199952 KB Output is correct
29 Correct 144 ms 199952 KB Output is correct
30 Correct 126 ms 199952 KB Output is correct
31 Correct 128 ms 199952 KB Output is correct
32 Correct 129 ms 199952 KB Output is correct
33 Correct 412 ms 253272 KB Output is correct
34 Correct 411 ms 253272 KB Output is correct
35 Correct 389 ms 253272 KB Output is correct
36 Correct 629 ms 253272 KB Output is correct
37 Correct 130 ms 253272 KB Output is correct
38 Correct 286 ms 253272 KB Output is correct
39 Correct 132 ms 253272 KB Output is correct
40 Correct 545 ms 253272 KB Output is correct
41 Correct 553 ms 253272 KB Output is correct
42 Correct 562 ms 253272 KB Output is correct
43 Correct 475 ms 253272 KB Output is correct
44 Correct 529 ms 253272 KB Output is correct
45 Correct 579 ms 253272 KB Output is correct
46 Correct 560 ms 253272 KB Output is correct
47 Correct 575 ms 253272 KB Output is correct
48 Correct 143 ms 253272 KB Output is correct
49 Correct 139 ms 253272 KB Output is correct
50 Correct 248 ms 253272 KB Output is correct
51 Correct 136 ms 253272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 125 ms 199812 KB Output is correct
2 Correct 127 ms 199864 KB Output is correct
3 Correct 127 ms 199892 KB Output is correct
4 Correct 128 ms 199892 KB Output is correct
5 Correct 128 ms 199892 KB Output is correct
6 Correct 127 ms 199892 KB Output is correct
7 Correct 127 ms 199892 KB Output is correct
8 Correct 126 ms 199892 KB Output is correct
9 Correct 125 ms 199892 KB Output is correct
10 Correct 128 ms 199896 KB Output is correct
11 Correct 126 ms 199948 KB Output is correct
12 Correct 125 ms 199948 KB Output is correct
13 Correct 125 ms 199948 KB Output is correct
14 Correct 135 ms 199952 KB Output is correct
15 Correct 133 ms 199952 KB Output is correct
16 Correct 138 ms 199952 KB Output is correct
17 Correct 135 ms 199952 KB Output is correct
18 Correct 129 ms 199952 KB Output is correct
19 Correct 127 ms 199952 KB Output is correct
20 Correct 127 ms 199952 KB Output is correct
21 Correct 132 ms 199952 KB Output is correct
22 Correct 127 ms 199952 KB Output is correct
23 Correct 127 ms 199952 KB Output is correct
24 Correct 127 ms 199952 KB Output is correct
25 Correct 132 ms 199952 KB Output is correct
26 Correct 126 ms 199952 KB Output is correct
27 Correct 126 ms 199952 KB Output is correct
28 Correct 129 ms 199952 KB Output is correct
29 Correct 144 ms 199952 KB Output is correct
30 Correct 126 ms 199952 KB Output is correct
31 Correct 128 ms 199952 KB Output is correct
32 Correct 129 ms 199952 KB Output is correct
33 Correct 128 ms 199952 KB Output is correct
34 Correct 129 ms 199956 KB Output is correct
35 Correct 126 ms 199956 KB Output is correct
36 Correct 502 ms 200464 KB Output is correct
37 Incorrect 278 ms 201996 KB Output isn't correct
38 Incorrect 317 ms 201996 KB Output isn't correct
39 Incorrect 298 ms 201996 KB Output isn't correct
40 Correct 127 ms 201996 KB Output is correct
41 Incorrect 297 ms 201996 KB Output isn't correct
42 Incorrect 311 ms 201996 KB Output isn't correct
43 Runtime error 232 ms 252088 KB Execution killed with signal 11 (could be triggered by violating memory limits)
44 Incorrect 332 ms 252808 KB Output isn't correct
45 Incorrect 306 ms 252808 KB Output isn't correct
46 Runtime error 246 ms 253272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
47 Runtime error 259 ms 253272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
48 Incorrect 326 ms 253272 KB Output isn't correct
49 Incorrect 331 ms 253272 KB Output isn't correct
50 Incorrect 318 ms 253272 KB Output isn't correct
51 Correct 412 ms 253272 KB Output is correct
52 Correct 411 ms 253272 KB Output is correct
53 Correct 389 ms 253272 KB Output is correct
54 Correct 629 ms 253272 KB Output is correct
55 Correct 130 ms 253272 KB Output is correct
56 Correct 286 ms 253272 KB Output is correct
57 Correct 132 ms 253272 KB Output is correct
58 Correct 545 ms 253272 KB Output is correct
59 Correct 553 ms 253272 KB Output is correct
60 Correct 562 ms 253272 KB Output is correct
61 Correct 475 ms 253272 KB Output is correct
62 Correct 529 ms 253272 KB Output is correct
63 Correct 579 ms 253272 KB Output is correct
64 Correct 560 ms 253272 KB Output is correct
65 Correct 575 ms 253272 KB Output is correct
66 Correct 143 ms 253272 KB Output is correct
67 Correct 139 ms 253272 KB Output is correct
68 Correct 248 ms 253272 KB Output is correct
69 Correct 136 ms 253272 KB Output is correct
70 Runtime error 400 ms 253312 KB Execution killed with signal 11 (could be triggered by violating memory limits)
71 Runtime error 338 ms 253312 KB Execution killed with signal 11 (could be triggered by violating memory limits)
72 Runtime error 317 ms 253312 KB Execution killed with signal 11 (could be triggered by violating memory limits)
73 Runtime error 238 ms 253312 KB Execution killed with signal 11 (could be triggered by violating memory limits)
74 Incorrect 288 ms 253312 KB Output isn't correct
75 Runtime error 381 ms 253372 KB Execution killed with signal 11 (could be triggered by violating memory limits)
76 Correct 517 ms 253372 KB Output is correct
77 Runtime error 367 ms 253372 KB Execution killed with signal 11 (could be triggered by violating memory limits)
78 Runtime error 235 ms 253372 KB Execution killed with signal 11 (could be triggered by violating memory limits)
79 Runtime error 348 ms 253372 KB Execution killed with signal 11 (could be triggered by violating memory limits)
80 Runtime error 399 ms 253372 KB Execution killed with signal 11 (could be triggered by violating memory limits)
81 Runtime error 390 ms 253372 KB Execution killed with signal 11 (could be triggered by violating memory limits)
82 Runtime error 284 ms 253372 KB Execution killed with signal 11 (could be triggered by violating memory limits)
83 Runtime error 276 ms 253372 KB Execution killed with signal 11 (could be triggered by violating memory limits)
84 Runtime error 380 ms 253372 KB Execution killed with signal 11 (could be triggered by violating memory limits)
85 Runtime error 387 ms 253388 KB Execution killed with signal 11 (could be triggered by violating memory limits)
86 Runtime error 389 ms 253388 KB Execution killed with signal 11 (could be triggered by violating memory limits)
87 Incorrect 320 ms 253388 KB Output isn't correct
88 Runtime error 390 ms 253388 KB Execution killed with signal 11 (could be triggered by violating memory limits)
89 Runtime error 389 ms 253388 KB Execution killed with signal 11 (could be triggered by violating memory limits)
90 Runtime error 405 ms 253388 KB Execution killed with signal 11 (could be triggered by violating memory limits)