Submission #3805331
Source Code Expand
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>
using namespace std;
struct BoolName : numpunct<char> {
string t, f;
BoolName (string t = "Yes", string f = "No") : t(t), f(f) {}
string do_truename() const {return t;}
string do_falsename() const {return f;}
};
struct Initializer {
Initializer() {
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(15) << boolalpha;
cout.imbue(locale(cout.getloc(), new BoolName));
}
} initializer;
template<typename T> istream& operator>>(istream &s, vector<T> &v) {
for (T &t : v) s >> t;
return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
for (const T &t : v) s << t << endl;
return s;
}
void set_bool_name(string t, string f) {
cout.imbue(locale(cout.getloc(), new BoolName(t, f)));
}
template<typename T> int least_bit(T n) {
static_assert(sizeof(T) == 4 || sizeof(T) == 8, "unsupported size");
if (sizeof(T) == 4) return __builtin_ffs(n) - 1;
if (sizeof(T) == 8) return __builtin_ffsll(n) - 1;
}
// n must be greater than 0.
template<typename T> int least_bit_fast(T n) {
static_assert(sizeof(T) == 4 || sizeof(T) == 8, "unsupported size");
if (sizeof(T) == 4) return __builtin_ctz(n);
if (sizeof(T) == 8) return __builtin_ctzll(n);
}
template<typename T> int most_bit(T n) {
static_assert(sizeof(T) == 4 || sizeof(T) == 8, "unsupported size");
if (sizeof(T) == 4) return n ? 31 - __builtin_clz(n) : -1;
if (sizeof(T) == 8) return n ? 63 - __builtin_clzll(n) : -1;
}
template<typename T> int count_bit(T n) {
static_assert(sizeof(T) == 4 || sizeof(T) == 8, "unsupported size");
if (sizeof(T) == 4) return __builtin_popcount(n);
if (sizeof(T) == 8) return __builtin_popcountll(n);
}
template<typename T = double> constexpr T pi() {return acos(T(-1));}
template<typename T> T gcd(T t) {return abs(t);}
template<typename T, typename... S> T gcd(T a, S... s) {
a = abs(a);
auto b = gcd(s...);
if (a == 0 || b == 0) return max(a, b);
int fa = least_bit_fast(a);
int fb = least_bit_fast(b);
a >>= fa;
b >>= fb;
while (a != b) {
auto& c = a > b ? a : b;
c = abs(a - b);
c >>= least_bit_fast(c);
}
return a << min(fa, fb);
}
template<typename T> T gcd(const vector<T>& v) {
T g = abs(v[0]);
for (int i = 1; i < int(v.size()); ++i) g = gcd(g, v[i]);
return g;
}
template<typename T> T lcm(T t) {return abs(t);}
template<typename T, typename... S> T lcm(T t, S... s) {
T l = lcm(s...);
return abs(t) / gcd(t, l) * l;
}
template<typename T> T lcm(const vector<T>& v) {
T l = abs(v[0]);
for (int i = 1; i < int(v.size()); ++i) l = lcm(l, v[i]);
return l;
}
template<typename T> T floor(T a, T b) {
auto d = div(a, b);
return d.quot - (d.rem && (a < 0) != (b < 0) ? 1 : 0);
}
template<typename T> T ceil(T a, T b) {
auto d = div(a, b);
return d.quot + (d.rem && (a > 0) == (b > 0) ? 1 : 0);
}
template<typename T> T round(T a, T b) {return floor(a + b / 2, b);}
template<typename T> T mod(T a, T b) {
T c = a % b;
return c < 0 ? c + abs(b) : c;
}
template<typename T> T factorial(T n) {return n <= 1 ? 1 : factorial(n - 1) * n;}
template<typename T> vector<T> factorial_vector(int n) {
vector<T> v(n + 1, 1);
for (int i = 1; i <= n; ++i) v[i] = v[i - 1] * i;
return v;
}
template<typename T> T square(T n) {return n * n;}
template<typename T> T cube(T n) {return n * n * n;}
template<typename T> T norm(T x1, T y1, T x2, T y2) {return square(x1 - x2) + square(y1 - y2);}
template<typename T> bool isSquare(T n) {return square(T(sqrt(n))) == n;}
template<typename T> T clamp(T v, T l, T u) {return v < l ? l : v > u ? u : v;}
template<typename T> class Addition {
public:
template<typename V> T operator+(const V& v) const {
return T(static_cast<const T&>(*this)) += v;
}
};
template<typename T> class Subtraction {
public:
template<typename V> T operator-(const V& v) const {
return T(static_cast<const T&>(*this)) -= v;
}
};
template<typename T> class Multiplication {
public:
template<typename V> T operator*(const V& v) const {
return T(static_cast<const T&>(*this)) *= v;
}
};
template<typename T> class Division {
public:
template<typename V> T operator/(const V& v) const {
return T(static_cast<const T&>(*this)) /= v;
}
};
template<typename T> class Modulus {
public:
template<typename V> T operator%(const V& v) const {
return T(static_cast<const T&>(*this)) %= v;
}
};
template<typename T> class IndivisibleArithmetic : public Addition<T>, public Subtraction<T>, public Multiplication<T> {};
template<typename T> class Arithmetic : public IndivisibleArithmetic<T>, public Division<T> {};
class Inverse {
private:
int64_t mod;
vector<int64_t> inv;
public:
Inverse() {}
Inverse(int64_t mod, int64_t n = 1000000) : mod(mod), inv(n, 1) {for (int i = 2; i < n; ++i) inv[i] = inv[mod % i] * (mod - mod / i) % mod;}
int64_t operator()(int64_t a) const {
if (a < int(inv.size())) return inv[a];
int64_t b = mod, x = 1, y = 0;
while (b) {
int64_t t = a / b;
swap(a -= t * b, b);
swap(x -= t * y, y);
}
return x < 0 ? x + mod : x;
}
};
int64_t inverse(int64_t n, int64_t mod) {
Inverse inv(mod, 0);
return inv(n);
}
class Mint : public Arithmetic<Mint> {
private:
static int64_t mod;
static Inverse inverse;
int64_t val;
public:
Mint() : val(0) {}
Mint(const int64_t& val) {
this->val = val % mod;
if (this->val < 0) this->val += mod;
}
static void setMod(const int64_t& m) {
mod = m;
inverse = Inverse(m);
}
Mint operator-() const { return Mint(val ? mod - val : 0); }
Mint operator+=(const Mint& m) {
val += m.val;
if (val >= mod) val -= mod;
return *this;
}
Mint operator-=(const Mint& m) {
val -= m.val;
if (val < 0) val += mod;
return *this;
}
Mint operator*=(const Mint& m) {
val *= m.val;
val %= mod;
return *this;
}
Mint operator/=(const Mint& m) {
val *= inverse(m.val);
val %= mod;
return *this;
}
Mint operator++() {return *this += 1;}
Mint operator--() {return *this -= 1;}
template<typename T> Mint operator-(const T& m) { return Arithmetic<Mint>::operator-(m); }
explicit operator char() const { return val; }
explicit operator int() const { return val; }
explicit operator int64_t() const { return val; }
Mint identity() const {return 1;}
};
int64_t Mint::mod = 1000000007;
Inverse Mint::inverse(1000000007);
ostream& operator<<(ostream& os, Mint a) {
os << int64_t(a);
return os;
}
istream& operator>>(istream& is, Mint& a) {
int64_t n;
is >> n;
a = n;
return is;
}
Mint operator+(const int& n, const Mint& m) { return m + n; }
Mint operator-(const int& n, const Mint& m) { return -m + n; }
Mint operator*(const int& n, const Mint& m) { return m * n; }
Mint operator/(const int& n, const Mint& m) { return Mint(n) / m; }
Mint operator+(const int64_t& n, const Mint& m) { return m + n; }
Mint operator-(const int64_t& n, const Mint& m) { return -m + n; }
Mint operator*(const int64_t& n, const Mint& m) { return m * n; }
Mint operator/(const int64_t& n, const Mint& m) { return Mint(n) / m; }
int main() {
int n, m;
cin >> n >> m;
if (abs(n - m) > 1) {
cout << 0 << endl;
return 0;
}
auto f = factorial_vector<Mint>(max(n, m));
cout << (2 - abs(n - m)) * f[n] * f[m] << endl;
}
Submission Info
Submission Time |
|
Task |
C - Reconciled? |
User |
not |
Language |
C++14 (GCC 5.4.1) |
Score |
300 |
Code Size |
7626 Byte |
Status |
AC |
Exec Time |
22 ms |
Memory |
8832 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
300 / 300 |
Status |
|
|
Set Name |
Test Cases |
Sample |
s1.txt, s2.txt, s3.txt, s4.txt |
All |
01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, s1.txt, s2.txt, s3.txt, s4.txt |
Case Name |
Status |
Exec Time |
Memory |
01.txt |
AC |
19 ms |
8064 KB |
02.txt |
AC |
21 ms |
8832 KB |
03.txt |
AC |
20 ms |
8064 KB |
04.txt |
AC |
21 ms |
8832 KB |
05.txt |
AC |
21 ms |
8704 KB |
06.txt |
AC |
19 ms |
8064 KB |
07.txt |
AC |
20 ms |
8064 KB |
08.txt |
AC |
19 ms |
8064 KB |
09.txt |
AC |
21 ms |
8704 KB |
10.txt |
AC |
22 ms |
8704 KB |
11.txt |
AC |
19 ms |
8064 KB |
12.txt |
AC |
19 ms |
8064 KB |
s1.txt |
AC |
19 ms |
8064 KB |
s2.txt |
AC |
19 ms |
8064 KB |
s3.txt |
AC |
19 ms |
8064 KB |
s4.txt |
AC |
22 ms |
8832 KB |