# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
98052 | dndhk | Worst Reporter 2 (JOI16_worst_reporter2) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/c++.h>
using namespace std;
#define INF 2000000000
typedef pair<int, int> pii;
const int MAX_N = 50;
int N;
vector<pii> v1, v2;
int ans = INF;
int idx[MAX_N+1];
int chk[MAX_N+1];
int sum = 0;
void dfs(int x){
if(x==N){
ans = min(ans,sum); return;
}
for(int i=0; i<N; i++){
if(chk[i]==0 && v1[x].second<=v2[i].second){
chk[i]=1;
if(v1[x].first!=v2[i].first){
sum++;
}
dfs(x+1);
chk[i] = 0;
if(v1[x].first!=v2[i].first){
sum--;
}
}else if(v1[x].second>v2[i].second){
return;
}
}
}
int main(){
scanf("%d", &N);
for(int i=0; i<N; i++){
int a, b; scanf("%d%d", &a, &b);
v1.push_back({a, b});
}
for(int i=0; i<N; i++){
int a, b; scanf("%d%d", &a, &b);
s.push_back({a, b});
}
dfs(0);
printf("%d", ans);
return 0;
}