Submission #3513293


Source Code Expand

w#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;
 
template<typename tp> inline void read(tp &x) {
  x = 0; char c = getchar(); int f = 0;
  for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
  for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if (f) x = -x;
}
#define pb push_back
#define int long long
typedef long long lo;
const int N = 3e5 + 233;
const int mo = 1e9 + 7;
int n, a[N], b[N], fac[N];


inline int sgn(int x) {
  return x > 0 ? 1 : -1;
}

signed main(void) {
  read(n);
  rep (i, n) read(a[i]);
  rep (i, n) read(b[i]);
  sort(a + 1, a + n + 1);
  sort(b + 1, b + n + 1);
  fac[0] = 1;
  rep (i, n) fac[i] = fac[i - 1] * i % mo;
  int posA = n, posB = 0;
  for (int i = 2; i <= n; i ++) {
    if (abs(a[i] - b[i]) + abs(a[i - 1] - b[i - 1])
        != abs(a[i] - b[i - 1]) + abs(a[i - 1] - b[i])) {
      posA = i - 1;
      break;
    }
  }
  for (int i = n; i >= 1; i --) {
    if (abs(a[i] - b[i]) + abs(a[i - 1] - b[i - 1])
        != abs(a[i] - b[i - 1]) + abs(a[i - 1] - b[i])) {
      posB = n - i;
      break;
    }
  }
  // cout << posA << " " << posB << "\n";
  cout << fac[posA] * fac[posB] % mo << "\n";
}

Submission Info

Submission Time
Task A - 1D Matching
User vjudge2
Language C++14 (Clang 3.8.0)
Score 0
Code Size 1365 Byte
Status CE

Compile Error

./Main.cpp:1:1: error: unknown type name 'w'
w#include <bits/stdc++.h>
^
./Main.cpp:1:2: error: expected unqualified-id
w#include <bits/stdc++.h>
 ^
./Main.cpp:9:19: error: use of undeclared identifier 'getchar'
  x = 0; char c = getchar(); int f = 0;
                  ^
./Main.cpp:10:49: error: use of undeclared identifier 'getchar'
  for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
                                                ^
./Main.cpp:11:71: error: use of undeclared identifier 'getchar'
  for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
                                                                      ^
./Main.cpp:28:3: warning: 'register' storage class specifier is deprecated and incompatible with C++1z [-Wdeprecated-register]
  rep (i, n) read(a[i]);
  ^
./Main.cpp:2:24: note: expanded from macro 'rep'
#define rep(i, n) for (rint i = 1; i <= (n); i ++)
                       ^
./Main.cpp:5:14: note: expanded from macro 'rint'
#define rint register int
   ...