답안 #20492

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
20492 2017-02-12T05:21:36 Z 볼빨간민돌이(#63, mindol) 초음속철도 (OJUZ11_rail) C++11
18 / 100
446 ms 7868 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.second == p2.second) return p1.first > p2.first;
	else return p1.second < p2.second;
}

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;
	stack<pair<int, int>> st;
	for(auto &e:v){
        if(st.empty()){
			st.push(e);
			continue;
		}
		else{
            if(st.top().first < e.first){
				pair<int, int> piv = st.top(); st.pop();
				int pivCnt=1, norCnt=0;

				while(!st.empty()){
                    if(st.top()==piv) pivCnt++;
                    else norCnt++;
                    st.pop();
				}
				ans=ans*1ll*(myPow(2, pivCnt)-1)%mod*myPow(2, norCnt)%mod;
				st.push(e);
            }
            else st.push(e);
		}
	}

	if(!st.empty()){
		pair<int, int> piv = st.top(); st.pop();
		int pivCnt=1, norCnt=0;

		while(!st.empty()){
			if(st.top()==piv) pivCnt++;
			else norCnt++;
			st.pop();
		}
		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", f(1));
		return 0;
	}
	else{
		printf("%d", sub3());
		return 0;
	}
	return 0;
}

Compilation message

rail.cpp: In function 'int main()':
rail.cpp:105: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:107: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]);
                               ^
# 결과 실행 시간 메모리 Grader output
1 Correct 379 ms 3696 KB Output is correct
2 Correct 236 ms 3696 KB Output is correct
3 Correct 423 ms 3696 KB Output is correct
4 Correct 436 ms 3696 KB Output is correct
5 Correct 0 ms 3696 KB Output is correct
6 Correct 0 ms 3696 KB Output is correct
7 Correct 443 ms 3696 KB Output is correct
8 Correct 49 ms 3696 KB Output is correct
9 Correct 0 ms 3696 KB Output is correct
10 Correct 0 ms 3696 KB Output is correct
11 Correct 0 ms 3696 KB Output is correct
12 Correct 213 ms 3696 KB Output is correct
13 Correct 376 ms 3696 KB Output is correct
14 Correct 179 ms 3696 KB Output is correct
15 Correct 439 ms 3696 KB Output is correct
16 Correct 426 ms 3696 KB Output is correct
17 Correct 439 ms 3696 KB Output is correct
18 Correct 426 ms 3696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 379 ms 3696 KB Output is correct
2 Correct 236 ms 3696 KB Output is correct
3 Correct 423 ms 3696 KB Output is correct
4 Correct 436 ms 3696 KB Output is correct
5 Correct 0 ms 3696 KB Output is correct
6 Correct 0 ms 3696 KB Output is correct
7 Correct 443 ms 3696 KB Output is correct
8 Correct 49 ms 3696 KB Output is correct
9 Correct 0 ms 3696 KB Output is correct
10 Correct 0 ms 3696 KB Output is correct
11 Correct 0 ms 3696 KB Output is correct
12 Correct 213 ms 3696 KB Output is correct
13 Correct 376 ms 3696 KB Output is correct
14 Correct 179 ms 3696 KB Output is correct
15 Correct 439 ms 3696 KB Output is correct
16 Correct 426 ms 3696 KB Output is correct
17 Correct 439 ms 3696 KB Output is correct
18 Correct 426 ms 3696 KB Output is correct
19 Correct 433 ms 3696 KB Output is correct
20 Correct 443 ms 3696 KB Output is correct
21 Correct 413 ms 3696 KB Output is correct
22 Correct 99 ms 3696 KB Output is correct
23 Correct 0 ms 3696 KB Output is correct
24 Correct 106 ms 3696 KB Output is correct
25 Correct 99 ms 3696 KB Output is correct
26 Correct 99 ms 3696 KB Output is correct
27 Correct 413 ms 3696 KB Output is correct
28 Correct 376 ms 3696 KB Output is correct
29 Correct 443 ms 3696 KB Output is correct
30 Correct 426 ms 3696 KB Output is correct
31 Correct 446 ms 3696 KB Output is correct
32 Correct 206 ms 3696 KB Output is correct
33 Correct 409 ms 3696 KB Output is correct
34 Correct 369 ms 3696 KB Output is correct
35 Correct 419 ms 3696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3696 KB Output is correct
2 Correct 0 ms 3696 KB Output is correct
3 Correct 0 ms 3696 KB Output is correct
4 Incorrect 0 ms 3836 KB Output isn't correct
5 Incorrect 96 ms 7868 KB Output isn't correct
6 Incorrect 133 ms 7868 KB Output isn't correct
7 Incorrect 116 ms 7868 KB Output isn't correct
8 Incorrect 0 ms 3696 KB Output isn't correct
9 Incorrect 119 ms 7868 KB Output isn't correct
10 Incorrect 123 ms 7868 KB Output isn't correct
11 Incorrect 49 ms 5820 KB Output isn't correct
12 Incorrect 126 ms 7868 KB Output isn't correct
13 Incorrect 133 ms 7868 KB Output isn't correct
14 Incorrect 76 ms 7868 KB Output isn't correct
15 Correct 123 ms 7868 KB Output is correct
16 Incorrect 76 ms 7868 KB Output isn't correct
17 Incorrect 136 ms 7868 KB Output isn't correct
18 Incorrect 119 ms 7868 KB Output isn't correct
19 Incorrect 126 ms 7868 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 379 ms 3696 KB Output is correct
2 Correct 236 ms 3696 KB Output is correct
3 Correct 423 ms 3696 KB Output is correct
4 Correct 436 ms 3696 KB Output is correct
5 Correct 0 ms 3696 KB Output is correct
6 Correct 0 ms 3696 KB Output is correct
7 Correct 443 ms 3696 KB Output is correct
8 Correct 49 ms 3696 KB Output is correct
9 Correct 0 ms 3696 KB Output is correct
10 Correct 0 ms 3696 KB Output is correct
11 Correct 0 ms 3696 KB Output is correct
12 Correct 213 ms 3696 KB Output is correct
13 Correct 376 ms 3696 KB Output is correct
14 Correct 179 ms 3696 KB Output is correct
15 Correct 439 ms 3696 KB Output is correct
16 Correct 426 ms 3696 KB Output is correct
17 Correct 439 ms 3696 KB Output is correct
18 Correct 426 ms 3696 KB Output is correct
19 Correct 433 ms 3696 KB Output is correct
20 Correct 443 ms 3696 KB Output is correct
21 Correct 413 ms 3696 KB Output is correct
22 Correct 99 ms 3696 KB Output is correct
23 Correct 0 ms 3696 KB Output is correct
24 Correct 106 ms 3696 KB Output is correct
25 Correct 99 ms 3696 KB Output is correct
26 Correct 99 ms 3696 KB Output is correct
27 Correct 413 ms 3696 KB Output is correct
28 Correct 376 ms 3696 KB Output is correct
29 Correct 443 ms 3696 KB Output is correct
30 Correct 426 ms 3696 KB Output is correct
31 Correct 446 ms 3696 KB Output is correct
32 Correct 206 ms 3696 KB Output is correct
33 Correct 409 ms 3696 KB Output is correct
34 Correct 369 ms 3696 KB Output is correct
35 Correct 419 ms 3696 KB Output is correct
36 Incorrect 3 ms 3836 KB Output isn't correct
37 Incorrect 0 ms 3836 KB Output isn't correct
38 Incorrect 0 ms 3836 KB Output isn't correct
39 Incorrect 0 ms 3836 KB Output isn't correct
40 Correct 3 ms 3836 KB Output is correct
41 Correct 0 ms 3836 KB Output is correct
42 Incorrect 3 ms 3836 KB Output isn't correct
43 Incorrect 0 ms 3696 KB Output isn't correct
44 Incorrect 0 ms 3836 KB Output isn't correct
45 Correct 0 ms 3836 KB Output is correct
46 Incorrect 3 ms 3836 KB Output isn't correct
47 Incorrect 3 ms 3836 KB Output isn't correct
48 Incorrect 3 ms 3836 KB Output isn't correct
49 Incorrect 0 ms 3836 KB Output isn't correct
50 Incorrect 0 ms 3836 KB Output isn't correct
51 Incorrect 0 ms 3836 KB Output isn't correct
52 Incorrect 0 ms 3696 KB Output isn't correct
53 Correct 0 ms 3836 KB Output is correct
54 Incorrect 0 ms 3836 KB Output isn't correct
55 Correct 0 ms 3836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 379 ms 3696 KB Output is correct
2 Correct 236 ms 3696 KB Output is correct
3 Correct 423 ms 3696 KB Output is correct
4 Correct 436 ms 3696 KB Output is correct
5 Correct 0 ms 3696 KB Output is correct
6 Correct 0 ms 3696 KB Output is correct
7 Correct 443 ms 3696 KB Output is correct
8 Correct 49 ms 3696 KB Output is correct
9 Correct 0 ms 3696 KB Output is correct
10 Correct 0 ms 3696 KB Output is correct
11 Correct 0 ms 3696 KB Output is correct
12 Correct 213 ms 3696 KB Output is correct
13 Correct 376 ms 3696 KB Output is correct
14 Correct 179 ms 3696 KB Output is correct
15 Correct 439 ms 3696 KB Output is correct
16 Correct 426 ms 3696 KB Output is correct
17 Correct 439 ms 3696 KB Output is correct
18 Correct 426 ms 3696 KB Output is correct
19 Correct 433 ms 3696 KB Output is correct
20 Correct 443 ms 3696 KB Output is correct
21 Correct 413 ms 3696 KB Output is correct
22 Correct 99 ms 3696 KB Output is correct
23 Correct 0 ms 3696 KB Output is correct
24 Correct 106 ms 3696 KB Output is correct
25 Correct 99 ms 3696 KB Output is correct
26 Correct 99 ms 3696 KB Output is correct
27 Correct 413 ms 3696 KB Output is correct
28 Correct 376 ms 3696 KB Output is correct
29 Correct 443 ms 3696 KB Output is correct
30 Correct 426 ms 3696 KB Output is correct
31 Correct 446 ms 3696 KB Output is correct
32 Correct 206 ms 3696 KB Output is correct
33 Correct 409 ms 3696 KB Output is correct
34 Correct 369 ms 3696 KB Output is correct
35 Correct 419 ms 3696 KB Output is correct
36 Correct 0 ms 3696 KB Output is correct
37 Correct 0 ms 3696 KB Output is correct
38 Correct 0 ms 3696 KB Output is correct
39 Incorrect 0 ms 3836 KB Output isn't correct
40 Incorrect 96 ms 7868 KB Output isn't correct
41 Incorrect 133 ms 7868 KB Output isn't correct
42 Incorrect 116 ms 7868 KB Output isn't correct
43 Incorrect 0 ms 3696 KB Output isn't correct
44 Incorrect 119 ms 7868 KB Output isn't correct
45 Incorrect 123 ms 7868 KB Output isn't correct
46 Incorrect 49 ms 5820 KB Output isn't correct
47 Incorrect 126 ms 7868 KB Output isn't correct
48 Incorrect 133 ms 7868 KB Output isn't correct
49 Incorrect 76 ms 7868 KB Output isn't correct
50 Correct 123 ms 7868 KB Output is correct
51 Incorrect 76 ms 7868 KB Output isn't correct
52 Incorrect 136 ms 7868 KB Output isn't correct
53 Incorrect 119 ms 7868 KB Output isn't correct
54 Incorrect 126 ms 7868 KB Output isn't correct
55 Incorrect 3 ms 3836 KB Output isn't correct
56 Incorrect 0 ms 3836 KB Output isn't correct
57 Incorrect 0 ms 3836 KB Output isn't correct
58 Incorrect 0 ms 3836 KB Output isn't correct
59 Correct 3 ms 3836 KB Output is correct
60 Correct 0 ms 3836 KB Output is correct
61 Incorrect 3 ms 3836 KB Output isn't correct
62 Incorrect 0 ms 3696 KB Output isn't correct
63 Incorrect 0 ms 3836 KB Output isn't correct
64 Correct 0 ms 3836 KB Output is correct
65 Incorrect 3 ms 3836 KB Output isn't correct
66 Incorrect 3 ms 3836 KB Output isn't correct
67 Incorrect 3 ms 3836 KB Output isn't correct
68 Incorrect 0 ms 3836 KB Output isn't correct
69 Incorrect 0 ms 3836 KB Output isn't correct
70 Incorrect 0 ms 3836 KB Output isn't correct
71 Incorrect 0 ms 3696 KB Output isn't correct
72 Correct 0 ms 3836 KB Output is correct
73 Incorrect 0 ms 3836 KB Output isn't correct
74 Correct 0 ms 3836 KB Output is correct
75 Incorrect 129 ms 7868 KB Output isn't correct
76 Incorrect 76 ms 5820 KB Output isn't correct
77 Incorrect 96 ms 7868 KB Output isn't correct
78 Incorrect 66 ms 7868 KB Output isn't correct
79 Correct 76 ms 6852 KB Output is correct
80 Incorrect 136 ms 7868 KB Output isn't correct
81 Incorrect 0 ms 3836 KB Output isn't correct
82 Incorrect 119 ms 7868 KB Output isn't correct
83 Correct 69 ms 7868 KB Output is correct
84 Incorrect 113 ms 7868 KB Output isn't correct
85 Incorrect 133 ms 7868 KB Output isn't correct
86 Incorrect 123 ms 7868 KB Output isn't correct
87 Incorrect 86 ms 7868 KB Output isn't correct
88 Incorrect 89 ms 7868 KB Output isn't correct
89 Incorrect 129 ms 7868 KB Output isn't correct
90 Incorrect 113 ms 7868 KB Output isn't correct
91 Incorrect 113 ms 7868 KB Output isn't correct
92 Correct 83 ms 6852 KB Output is correct
93 Incorrect 133 ms 7868 KB Output isn't correct
94 Incorrect 126 ms 7868 KB Output isn't correct
95 Incorrect 123 ms 7868 KB Output isn't correct