이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define rall(s) s.rbegin(), s.rend()
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define s second
#define f first
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int N = 1e6, mod = 1e9 + 7;
const int inf = 1e9;
void solve() {
int n;
cin >> n;
int a[n + 1][2];
for (int i = 1; i <= n; i++) cin >> a[i][0];
for (int i = 1; i <= n; i++) cin >> a[i][1];
for (int i = 1; i <= n; i++) {
if (a[i][1] < a[i][0]) swap(a[i][1], a[i][0]);
}
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j < i; j++) {
for (int k = i + 1; k <= n; k++) {
for (int x = 0; x < 2; x++) {
for (int y = 0; y < 2; y++) {
int v = 1;
for (int s = 1; s <= n; s++) {
if (s == i || s == j || s == k) continue;
int cnt = 0;
if (s < i) {
if (s < j) {
if (a[s][1] < a[j][x]) cnt = 2;
else if (a[s][0] < a[j][x]) cnt = 1;
else cnt = 0;
}else {
if (a[s][1] <= a[j][x]) cnt = 2;
else if (a[s][0] <= a[j][x]) cnt = 1;
else cnt = 0;
}
}else {
if (s > k) {
if (a[s][1] < a[k][y]) cnt = 2;
else if (a[s][0] < a[k][y]) cnt = 1;
else cnt = 0;
}else {
if (a[s][1] <= a[k][y]) cnt = 2;
else if (a[s][0] <= a[k][y]) cnt = 1;
else cnt = 0;
}
}
v = (v * cnt) % mod;
}
if (!v) continue;
for (int z = 0; z < 2; z++) {
if (a[i][z] > a[j][x] || a[i][z] > a[k][y]) continue;
ans = (ans + ((min(a[j][x], a[k][y]) - a[i][z]) * 1ll * v) % mod) % mod;
}
}
}
}
}
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
}
# | 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... |