이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds
/*
is I know the division, checking will be if there a segment that intersegt and not entirly contain.
i think this is a dp problem..
every segment will have some segment that it cannot be together with.. , count the number of partition
*/
const int MOD = 1e9+7;
int main(){
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n;cin>>n;
if(n>20) return 0;
vector<pair<int,int> > seg(n+1);
for(int i=1;i<=n;i++) cin>>seg[i].first>>seg[i].second;
vector<int> action(2*n+1);
for(int i=1;i<=n;i++){
action[seg[i].first]=i;
action[seg[i].second]=-i;
}
sort(seg.begin(),seg.end());
int ans=0;
for(int m=0;m<(1<<n);m++){
bool ok=1;
stack<int> f[2];
for(int i=1;i<=2*n;i++){
bool k = (m>>(abs(action[i])-1))&1;
if(action[i]>0){
f[k].push(action[i]);
}else{
if(f[k].top()!=-action[i]){
ok=0;
break;
}
f[k].pop();
}
}
if(ok) ans++;
}
assert(((ans-(ans&-ans)))==0);
cout<<ans<<"\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |