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/stdc++.h>
using namespace std;
const long long mod=1000000007;
long long twok[500005];
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
pair<long long,long long> arr[n];
for(int i=0; i<n; i++) cin >> arr[i].first;
for(int i=0; i<n; i++) cin >> arr[i].second;
for(int i=0; i<n; i++){
if(arr[i].first>arr[i].second)swap(arr[i].first,arr[i].second);
}
long long ans=0;
for(int bm=0; bm<(1<<n); bm++){
long long brr[n];
for(int i=0; i<n; i++){
if(bm&(1<<i)) brr[i]=arr[i].first;
else brr[i]=arr[i].second;
}
pair<long long,long long> mx[n];
mx[0].first=brr[0];
mx[n-1].second=brr[n-1];
for(int i=1; i<n; i++) mx[i].first=max(mx[i-1].first,brr[i]);
for(int i=n-2; i>=0; i--) mx[i].second=max(mx[i+1].second,brr[i]);
for(int i=0; i<n; i++) ans+=min(mx[i].first,mx[i].second)-brr[i];
}
cout << ans%mod;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |