이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
const ll md = 1e9+7;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
vector<ll> A(n), B(n);
for(ll &x: A) cin >> x;
for(ll &x: B) cin >> x;
ll ans = 0;
for(int k = 0; k < (1<<n); k++){
vector<ll> C(n);
ll cur = 0;
for(int i = 0; i < n; i++){
if(k&(1<<i)) C[i] = B[i];
else C[i] = A[i];
cur-=C[i], cur%=md;
}
vector<ll> suff(n, 0);
for(int i = n-1; i >= 0; i--){
if(i+1 < n) suff[i] = suff[i+1];
suff[i] = max(suff[i], C[i]);
}
ll mx = 0;
for(int i = 0; i < n; i++){
mx = max(mx, C[i]);
cur+=min(mx, suff[i]), cur%=md;
}
if(cur < 0) cur+=md;
ans+=cur;
ans%=md;
}
cout << ans << "\n";
}
# | 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... |