Submission #20493

# Submission time Handle Problem Language Result Execution time Memory
20493 2017-02-12T05:40:22 Z 볼빨간민돌이(#63, mindol) 초음속철도 (OJUZ11_rail) C++11
18 / 100
513 ms 7104 KB
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;

const int MAXM = 200000;
const int mod = 1e9+7;
int n, m, s[MAXM+1], e[MAXM+1];

int myPow(int a, int r){
	if(r==0) return 1;
	int half=myPow(a, r/2);
	if(r&1) return half*1ll*half%mod*a%mod;
	else return half*1ll*half%mod;
}

bool use[MAXM+1];
int check(){
	vector<pair<int, int>> v;

    for(int i=1; i<=m; i++)
		if(use[i]) v.push_back(make_pair(s[i], e[i]));
    sort(v.begin(), v.end());
    if(v.empty()) return 0;

    int now=1;
    for(auto &e:v){
		if(e.first > now) break;
		else now=max(now, e.second);
    }
    return now==n;
}

int f(int now){
	if(now==m+1) return check();

	int sum=0;
	use[now]=true;
	sum+=f(now+1);
	use[now]=false;
	sum+=f(now+1);
	return sum;
}

bool comp3(const pair<int, int> &p1, const pair<int, int> &p2){
	if(p1.first == p2.first) return p1.second > p2.second;
	else return p1.first < p2.first;
}

int sub3(){
	for(int i=1; i<=m; i++)
		use[i]=true;
	if(!check()) return 0;

	vector<pair<int, int>> v;
    for(int i=1; i<=m; i++)
		v.push_back(make_pair(s[i], e[i]));
	sort(v.begin(), v.end(), comp3);

	int ans=1;
	pair<int, int> piv;
	int pivCnt=0, norCnt=0;
	for(auto &e:v){
        if(pivCnt==0) pivCnt++, piv=e;
        else{
            if(e.first >= piv.second){
				ans=ans*1ll*(myPow(2, pivCnt)-1)%mod*myPow(2, norCnt)%mod;
				pivCnt=1, norCnt=0, piv=e;
			}
			else{
				if(e==piv) pivCnt++;
				else norCnt++;
			}
        }
	}
	if(pivCnt) ans=ans*1ll*(myPow(2, pivCnt)-1)%mod*myPow(2, norCnt)%mod;

	if(ans<0) ans+=mod;
	return ans;
}

int main(){
#ifndef EVAL
	freopen("input.txt", "r", stdin);
#endif
	scanf("%d %d", &n, &m);
    for(int i=1; i<=m; i++)
		scanf("%d %d", &s[i], &e[i]);

    if(m<=20){
		printf("%d\n", f(1));
		return 0;
	}
	else{
		printf("%d\n", sub3());
		return 0;
	}
	return 0;
}

Compilation message

rail.cpp: In function 'int main()':
rail.cpp:87:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
                        ^
rail.cpp:89:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &s[i], &e[i]);
                               ^
# Verdict Execution time Memory Grader output
1 Correct 379 ms 2932 KB Output is correct
2 Correct 223 ms 2932 KB Output is correct
3 Correct 399 ms 2932 KB Output is correct
4 Correct 406 ms 2932 KB Output is correct
5 Correct 0 ms 2932 KB Output is correct
6 Correct 0 ms 2932 KB Output is correct
7 Correct 413 ms 2932 KB Output is correct
8 Correct 49 ms 2932 KB Output is correct
9 Correct 0 ms 2932 KB Output is correct
10 Correct 0 ms 2932 KB Output is correct
11 Correct 0 ms 2932 KB Output is correct
12 Correct 203 ms 2932 KB Output is correct
13 Correct 353 ms 2932 KB Output is correct
14 Correct 199 ms 2932 KB Output is correct
15 Correct 409 ms 2932 KB Output is correct
16 Correct 409 ms 2932 KB Output is correct
17 Correct 406 ms 2932 KB Output is correct
18 Correct 436 ms 2932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 379 ms 2932 KB Output is correct
2 Correct 223 ms 2932 KB Output is correct
3 Correct 399 ms 2932 KB Output is correct
4 Correct 406 ms 2932 KB Output is correct
5 Correct 0 ms 2932 KB Output is correct
6 Correct 0 ms 2932 KB Output is correct
7 Correct 413 ms 2932 KB Output is correct
8 Correct 49 ms 2932 KB Output is correct
9 Correct 0 ms 2932 KB Output is correct
10 Correct 0 ms 2932 KB Output is correct
11 Correct 0 ms 2932 KB Output is correct
12 Correct 203 ms 2932 KB Output is correct
13 Correct 353 ms 2932 KB Output is correct
14 Correct 199 ms 2932 KB Output is correct
15 Correct 409 ms 2932 KB Output is correct
16 Correct 409 ms 2932 KB Output is correct
17 Correct 406 ms 2932 KB Output is correct
18 Correct 436 ms 2932 KB Output is correct
19 Correct 403 ms 2932 KB Output is correct
20 Correct 459 ms 2932 KB Output is correct
21 Correct 459 ms 2932 KB Output is correct
22 Correct 96 ms 2932 KB Output is correct
23 Correct 0 ms 2932 KB Output is correct
24 Correct 96 ms 2932 KB Output is correct
25 Correct 103 ms 2932 KB Output is correct
26 Correct 103 ms 2932 KB Output is correct
27 Correct 419 ms 2932 KB Output is correct
28 Correct 406 ms 2932 KB Output is correct
29 Correct 513 ms 2932 KB Output is correct
30 Correct 413 ms 2932 KB Output is correct
31 Correct 449 ms 2932 KB Output is correct
32 Correct 203 ms 2932 KB Output is correct
33 Correct 406 ms 2932 KB Output is correct
34 Correct 409 ms 2932 KB Output is correct
35 Correct 433 ms 2932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2932 KB Output is correct
2 Correct 0 ms 2932 KB Output is correct
3 Correct 0 ms 2932 KB Output is correct
4 Incorrect 0 ms 3072 KB Output isn't correct
5 Incorrect 96 ms 7104 KB Output isn't correct
6 Correct 129 ms 7104 KB Output is correct
7 Correct 106 ms 7104 KB Output is correct
8 Correct 0 ms 2932 KB Output is correct
9 Correct 126 ms 7104 KB Output is correct
10 Correct 126 ms 7104 KB Output is correct
11 Correct 46 ms 5056 KB Output is correct
12 Correct 126 ms 7104 KB Output is correct
13 Correct 123 ms 7104 KB Output is correct
14 Correct 66 ms 7104 KB Output is correct
15 Correct 139 ms 7104 KB Output is correct
16 Correct 83 ms 7104 KB Output is correct
17 Correct 119 ms 7104 KB Output is correct
18 Correct 123 ms 7104 KB Output is correct
19 Correct 116 ms 7104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 379 ms 2932 KB Output is correct
2 Correct 223 ms 2932 KB Output is correct
3 Correct 399 ms 2932 KB Output is correct
4 Correct 406 ms 2932 KB Output is correct
5 Correct 0 ms 2932 KB Output is correct
6 Correct 0 ms 2932 KB Output is correct
7 Correct 413 ms 2932 KB Output is correct
8 Correct 49 ms 2932 KB Output is correct
9 Correct 0 ms 2932 KB Output is correct
10 Correct 0 ms 2932 KB Output is correct
11 Correct 0 ms 2932 KB Output is correct
12 Correct 203 ms 2932 KB Output is correct
13 Correct 353 ms 2932 KB Output is correct
14 Correct 199 ms 2932 KB Output is correct
15 Correct 409 ms 2932 KB Output is correct
16 Correct 409 ms 2932 KB Output is correct
17 Correct 406 ms 2932 KB Output is correct
18 Correct 436 ms 2932 KB Output is correct
19 Correct 403 ms 2932 KB Output is correct
20 Correct 459 ms 2932 KB Output is correct
21 Correct 459 ms 2932 KB Output is correct
22 Correct 96 ms 2932 KB Output is correct
23 Correct 0 ms 2932 KB Output is correct
24 Correct 96 ms 2932 KB Output is correct
25 Correct 103 ms 2932 KB Output is correct
26 Correct 103 ms 2932 KB Output is correct
27 Correct 419 ms 2932 KB Output is correct
28 Correct 406 ms 2932 KB Output is correct
29 Correct 513 ms 2932 KB Output is correct
30 Correct 413 ms 2932 KB Output is correct
31 Correct 449 ms 2932 KB Output is correct
32 Correct 203 ms 2932 KB Output is correct
33 Correct 406 ms 2932 KB Output is correct
34 Correct 409 ms 2932 KB Output is correct
35 Correct 433 ms 2932 KB Output is correct
36 Incorrect 3 ms 3072 KB Output isn't correct
37 Incorrect 0 ms 3072 KB Output isn't correct
38 Incorrect 0 ms 3072 KB Output isn't correct
39 Incorrect 0 ms 3072 KB Output isn't correct
40 Correct 3 ms 3072 KB Output is correct
41 Correct 0 ms 3072 KB Output is correct
42 Incorrect 0 ms 3072 KB Output isn't correct
43 Incorrect 0 ms 2932 KB Output isn't correct
44 Incorrect 3 ms 3072 KB Output isn't correct
45 Correct 0 ms 3072 KB Output is correct
46 Incorrect 0 ms 3072 KB Output isn't correct
47 Incorrect 3 ms 3072 KB Output isn't correct
48 Incorrect 0 ms 3072 KB Output isn't correct
49 Incorrect 0 ms 3072 KB Output isn't correct
50 Incorrect 0 ms 3072 KB Output isn't correct
51 Incorrect 3 ms 3072 KB Output isn't correct
52 Incorrect 0 ms 2932 KB Output isn't correct
53 Correct 0 ms 3072 KB Output is correct
54 Incorrect 0 ms 3072 KB Output isn't correct
55 Correct 0 ms 3072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 379 ms 2932 KB Output is correct
2 Correct 223 ms 2932 KB Output is correct
3 Correct 399 ms 2932 KB Output is correct
4 Correct 406 ms 2932 KB Output is correct
5 Correct 0 ms 2932 KB Output is correct
6 Correct 0 ms 2932 KB Output is correct
7 Correct 413 ms 2932 KB Output is correct
8 Correct 49 ms 2932 KB Output is correct
9 Correct 0 ms 2932 KB Output is correct
10 Correct 0 ms 2932 KB Output is correct
11 Correct 0 ms 2932 KB Output is correct
12 Correct 203 ms 2932 KB Output is correct
13 Correct 353 ms 2932 KB Output is correct
14 Correct 199 ms 2932 KB Output is correct
15 Correct 409 ms 2932 KB Output is correct
16 Correct 409 ms 2932 KB Output is correct
17 Correct 406 ms 2932 KB Output is correct
18 Correct 436 ms 2932 KB Output is correct
19 Correct 403 ms 2932 KB Output is correct
20 Correct 459 ms 2932 KB Output is correct
21 Correct 459 ms 2932 KB Output is correct
22 Correct 96 ms 2932 KB Output is correct
23 Correct 0 ms 2932 KB Output is correct
24 Correct 96 ms 2932 KB Output is correct
25 Correct 103 ms 2932 KB Output is correct
26 Correct 103 ms 2932 KB Output is correct
27 Correct 419 ms 2932 KB Output is correct
28 Correct 406 ms 2932 KB Output is correct
29 Correct 513 ms 2932 KB Output is correct
30 Correct 413 ms 2932 KB Output is correct
31 Correct 449 ms 2932 KB Output is correct
32 Correct 203 ms 2932 KB Output is correct
33 Correct 406 ms 2932 KB Output is correct
34 Correct 409 ms 2932 KB Output is correct
35 Correct 433 ms 2932 KB Output is correct
36 Correct 0 ms 2932 KB Output is correct
37 Correct 0 ms 2932 KB Output is correct
38 Correct 0 ms 2932 KB Output is correct
39 Incorrect 0 ms 3072 KB Output isn't correct
40 Incorrect 96 ms 7104 KB Output isn't correct
41 Correct 129 ms 7104 KB Output is correct
42 Correct 106 ms 7104 KB Output is correct
43 Correct 0 ms 2932 KB Output is correct
44 Correct 126 ms 7104 KB Output is correct
45 Correct 126 ms 7104 KB Output is correct
46 Correct 46 ms 5056 KB Output is correct
47 Correct 126 ms 7104 KB Output is correct
48 Correct 123 ms 7104 KB Output is correct
49 Correct 66 ms 7104 KB Output is correct
50 Correct 139 ms 7104 KB Output is correct
51 Correct 83 ms 7104 KB Output is correct
52 Correct 119 ms 7104 KB Output is correct
53 Correct 123 ms 7104 KB Output is correct
54 Correct 116 ms 7104 KB Output is correct
55 Incorrect 3 ms 3072 KB Output isn't correct
56 Incorrect 0 ms 3072 KB Output isn't correct
57 Incorrect 0 ms 3072 KB Output isn't correct
58 Incorrect 0 ms 3072 KB Output isn't correct
59 Correct 3 ms 3072 KB Output is correct
60 Correct 0 ms 3072 KB Output is correct
61 Incorrect 0 ms 3072 KB Output isn't correct
62 Incorrect 0 ms 2932 KB Output isn't correct
63 Incorrect 3 ms 3072 KB Output isn't correct
64 Correct 0 ms 3072 KB Output is correct
65 Incorrect 0 ms 3072 KB Output isn't correct
66 Incorrect 3 ms 3072 KB Output isn't correct
67 Incorrect 0 ms 3072 KB Output isn't correct
68 Incorrect 0 ms 3072 KB Output isn't correct
69 Incorrect 0 ms 3072 KB Output isn't correct
70 Incorrect 3 ms 3072 KB Output isn't correct
71 Incorrect 0 ms 2932 KB Output isn't correct
72 Correct 0 ms 3072 KB Output is correct
73 Incorrect 0 ms 3072 KB Output isn't correct
74 Correct 0 ms 3072 KB Output is correct
75 Incorrect 126 ms 7104 KB Output isn't correct
76 Incorrect 76 ms 5056 KB Output isn't correct
77 Incorrect 106 ms 7104 KB Output isn't correct
78 Incorrect 63 ms 7104 KB Output isn't correct
79 Correct 79 ms 6088 KB Output is correct
80 Incorrect 123 ms 7104 KB Output isn't correct
81 Incorrect 0 ms 3072 KB Output isn't correct
82 Incorrect 116 ms 7104 KB Output isn't correct
83 Correct 69 ms 7104 KB Output is correct
84 Incorrect 119 ms 7104 KB Output isn't correct
85 Incorrect 129 ms 7104 KB Output isn't correct
86 Incorrect 119 ms 7104 KB Output isn't correct
87 Incorrect 89 ms 7104 KB Output isn't correct
88 Incorrect 86 ms 7104 KB Output isn't correct
89 Incorrect 133 ms 7104 KB Output isn't correct
90 Incorrect 126 ms 7104 KB Output isn't correct
91 Incorrect 123 ms 7104 KB Output isn't correct
92 Correct 69 ms 6088 KB Output is correct
93 Incorrect 116 ms 7104 KB Output isn't correct
94 Incorrect 116 ms 7104 KB Output isn't correct
95 Incorrect 129 ms 7104 KB Output isn't correct