Submission #5652766
Source Code Expand
#include<stdio.h> #include<iostream> #include<vector> #include<algorithm> #include<string> #include<string.h> #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define NDEBUG #define eprintf(...) do {} while (0) #endif #include<cassert> using namespace std; typedef long long LL; typedef vector<int> VI; #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i) template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; } template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; } template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) { for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); } putchar('\n'); } template<unsigned MOD_> struct ModInt { static const unsigned MOD = MOD_; unsigned x; void undef() { x = (unsigned)-1; } bool isnan() const { return x == (unsigned)-1; } inline int geti() const { return (int)x; } ModInt() { x = 0; } ModInt(const ModInt &y) { x = y.x; } ModInt(int y) { if (y<0 || (int)MOD<=y) y %= (int)MOD; if (y<0) y += MOD; x=y; } ModInt(unsigned y) { if (MOD<=y) x = y % MOD; else x = y; } ModInt(long long y) { if (y<0 || MOD<=y) y %= MOD; if (y<0) y += MOD; x=y; } ModInt(unsigned long long y) { if (MOD<=y) x = y % MOD; else x = y; } ModInt &operator+=(const ModInt y) { if ((x += y.x) >= MOD) x -= MOD; return *this; } ModInt &operator-=(const ModInt y) { if ((x -= y.x) & (1u<<31)) x += MOD; return *this; } ModInt &operator*=(const ModInt y) { x = (unsigned long long)x * y.x % MOD; return *this; } ModInt &operator/=(const ModInt y) { x = (unsigned long long)x * y.inv().x % MOD; return *this; } ModInt operator-() const { return (x ? MOD-x: 0); } ModInt inv() const { return pow(MOD-2); } ModInt pow(long long y) const { ModInt b = *this, r = 1; if (y < 0) { b = b.inv(); y = -y; } for (; y; y>>=1) { if (y&1) r *= b; b *= b; } return r; } ModInt extgcd() const { unsigned a = MOD, b = x; int u = 0, v = 1; while (b) { int t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } if (u < 0) u += MOD; return ModInt(u); } friend ModInt operator+(ModInt x, const ModInt y) { return x += y; } friend ModInt operator-(ModInt x, const ModInt y) { return x -= y; } friend ModInt operator*(ModInt x, const ModInt y) { return x *= y; } friend ModInt operator/(ModInt x, const ModInt y) { return x *= y.inv(); } friend bool operator<(const ModInt x, const ModInt y) { return x.x < y.x; } friend bool operator==(const ModInt x, const ModInt y) { return x.x == y.x; } friend bool operator!=(const ModInt x, const ModInt y) { return x.x != y.x; } }; const LL MOD = 1000000007; //const LL MOD = 998244353; typedef ModInt<MOD> Mint; const int MAX = 1000011; Mint inv[MAX], fact[MAX], fact_inv[MAX]; void init() { fact[0] = 1; for (int i=1; i<MAX; i++) fact[i] = fact[i-1] * i; fact_inv[MAX-1] = fact[MAX-1].inv(); for (int i=MAX-2; i>=0; i--) fact_inv[i] = fact_inv[i+1] * (i+1); inv[0] = 0; for (int i=1; i<MAX; i++) inv[i] = fact_inv[i] * fact[i-1]; } Mint nCk(int n, int k) { return fact[n] * fact_inv[k] * fact_inv[n-k]; } Mint f(int a, int A, int b, int B) { return Mint(b).pow(A)*a + Mint(a).pow(B)*b - a*b; } Mint mem[111][111]; Mint g(int a, int A, int b, int B, int c, int C) { Mint ans = 0; memset(mem, 0, sizeof mem); for (int x=A-1; x>0; x--) for (int y=B-1; y>0; y--) { Mint p = Mint(c).pow((A-x)*(B-y)) - 1; Mint way = nCk(A, x) * nCk(B, y); for (int x1=x; x1<A; x1++) for (int y1=y; y1<B; y1++) { mem[x][y] -= mem[x1][y1] * nCk(x1, x) * nCk(y1, y); } mem[x][y] += p * way; Mint tmp = (Mint(b).pow(x) + Mint(a).pow(y) - 1).pow(C); tmp -= Mint(b).pow(x).pow(C); tmp -= Mint(a).pow(y).pow(C); tmp += 1; ans += mem[x][y] * tmp * a * b * c; } return ans; } void MAIN() { init(); int a, b, c, A, B, C; scanf("%d%d%d%d%d%d", &a, &b, &c, &A, &B, &C); Mint ans; if (A % a == 0 && B % b == 0 && C % c == 0) { A /= a; B /= b; C /= c; ans += f(a, A, b, B).pow(C) * c; ans += f(b, B, c, C).pow(A) * a; ans += f(c, C, a, A).pow(B) * b; ans -= Mint(c).pow(A*B)*a*b; ans -= Mint(a).pow(B*C)*b*c; ans -= Mint(b).pow(C*A)*c*a; ans += a*b*c; ans += g(a, A, b, B, c, C); } printf("%d\n", ans.geti()); } int main() { int TC = 1; // scanf("%d", &TC); REP (tc, TC) MAIN(); return 0; }
Submission Info
Submission Time | |
---|---|
Task | J - Rectangles |
User | natsugiri |
Language | C++14 (GCC 5.4.1) |
Score | 2100 |
Code Size | 4753 Byte |
Status | AC |
Exec Time | 285 ms |
Memory | 12032 KB |
Compile Error
./Main.cpp: In function ‘void MAIN()’: ./Main.cpp:127:50: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d%d%d%d%d", &a, &b, &c, &A, &B, &C); ^
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 2100 / 2100 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt |
All | 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt, 1_026.txt, 1_027.txt, 1_028.txt, 1_029.txt, 1_030.txt, 1_031.txt, 1_032.txt, 1_033.txt, 1_034.txt, 1_035.txt, 1_036.txt, 1_037.txt, 1_038.txt, 1_039.txt, 1_040.txt, 1_041.txt, 1_042.txt, 1_043.txt, 1_044.txt, 1_045.txt, 1_046.txt, 1_047.txt, 1_048.txt, 1_049.txt, 1_050.txt, 1_051.txt, 1_052.txt, 1_053.txt, 1_054.txt, 1_055.txt, 1_056.txt, 1_057.txt, 1_058.txt, 1_059.txt, 1_060.txt, 1_061.txt, 1_062.txt, 1_063.txt, 1_064.txt, 1_065.txt, 1_066.txt, 1_067.txt, 1_068.txt, 1_069.txt, 1_070.txt, 1_071.txt, 1_072.txt, 1_073.txt, 1_074.txt, 1_075.txt, 1_076.txt, 1_077.txt, 1_078.txt, 1_079.txt, 1_080.txt, 1_081.txt, 1_082.txt, 1_083.txt, 1_084.txt, 1_085.txt, 1_086.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_000.txt | AC | 16 ms | 12032 KB |
0_001.txt | AC | 16 ms | 12032 KB |
0_002.txt | AC | 16 ms | 12032 KB |
0_003.txt | AC | 24 ms | 12032 KB |
1_004.txt | AC | 17 ms | 12032 KB |
1_005.txt | AC | 19 ms | 12032 KB |
1_006.txt | AC | 152 ms | 12032 KB |
1_007.txt | AC | 285 ms | 12032 KB |
1_008.txt | AC | 284 ms | 12032 KB |
1_009.txt | AC | 51 ms | 12032 KB |
1_010.txt | AC | 85 ms | 12032 KB |
1_011.txt | AC | 85 ms | 12032 KB |
1_012.txt | AC | 16 ms | 12032 KB |
1_013.txt | AC | 16 ms | 12032 KB |
1_014.txt | AC | 16 ms | 12032 KB |
1_015.txt | AC | 50 ms | 12032 KB |
1_016.txt | AC | 83 ms | 12032 KB |
1_017.txt | AC | 83 ms | 12032 KB |
1_018.txt | AC | 25 ms | 12032 KB |
1_019.txt | AC | 34 ms | 12032 KB |
1_020.txt | AC | 33 ms | 12032 KB |
1_021.txt | AC | 16 ms | 12032 KB |
1_022.txt | AC | 16 ms | 12032 KB |
1_023.txt | AC | 16 ms | 12032 KB |
1_024.txt | AC | 16 ms | 12032 KB |
1_025.txt | AC | 16 ms | 12032 KB |
1_026.txt | AC | 16 ms | 12032 KB |
1_027.txt | AC | 16 ms | 12032 KB |
1_028.txt | AC | 16 ms | 12032 KB |
1_029.txt | AC | 16 ms | 12032 KB |
1_030.txt | AC | 16 ms | 12032 KB |
1_031.txt | AC | 16 ms | 12032 KB |
1_032.txt | AC | 16 ms | 12032 KB |
1_033.txt | AC | 16 ms | 12032 KB |
1_034.txt | AC | 16 ms | 12032 KB |
1_035.txt | AC | 16 ms | 12032 KB |
1_036.txt | AC | 16 ms | 12032 KB |
1_037.txt | AC | 16 ms | 12032 KB |
1_038.txt | AC | 16 ms | 12032 KB |
1_039.txt | AC | 16 ms | 12032 KB |
1_040.txt | AC | 16 ms | 12032 KB |
1_041.txt | AC | 16 ms | 12032 KB |
1_042.txt | AC | 16 ms | 12032 KB |
1_043.txt | AC | 16 ms | 12032 KB |
1_044.txt | AC | 16 ms | 12032 KB |
1_045.txt | AC | 16 ms | 12032 KB |
1_046.txt | AC | 16 ms | 12032 KB |
1_047.txt | AC | 16 ms | 12032 KB |
1_048.txt | AC | 16 ms | 12032 KB |
1_049.txt | AC | 16 ms | 12032 KB |
1_050.txt | AC | 16 ms | 12032 KB |
1_051.txt | AC | 16 ms | 12032 KB |
1_052.txt | AC | 16 ms | 12032 KB |
1_053.txt | AC | 16 ms | 12032 KB |
1_054.txt | AC | 16 ms | 12032 KB |
1_055.txt | AC | 16 ms | 12032 KB |
1_056.txt | AC | 16 ms | 12032 KB |
1_057.txt | AC | 16 ms | 12032 KB |
1_058.txt | AC | 16 ms | 12032 KB |
1_059.txt | AC | 16 ms | 12032 KB |
1_060.txt | AC | 16 ms | 12032 KB |
1_061.txt | AC | 16 ms | 12032 KB |
1_062.txt | AC | 16 ms | 12032 KB |
1_063.txt | AC | 16 ms | 12032 KB |
1_064.txt | AC | 16 ms | 12032 KB |
1_065.txt | AC | 16 ms | 12032 KB |
1_066.txt | AC | 16 ms | 12032 KB |
1_067.txt | AC | 16 ms | 12032 KB |
1_068.txt | AC | 17 ms | 12032 KB |
1_069.txt | AC | 16 ms | 12032 KB |
1_070.txt | AC | 16 ms | 12032 KB |
1_071.txt | AC | 17 ms | 12032 KB |
1_072.txt | AC | 16 ms | 12032 KB |
1_073.txt | AC | 16 ms | 12032 KB |
1_074.txt | AC | 17 ms | 12032 KB |
1_075.txt | AC | 16 ms | 12032 KB |
1_076.txt | AC | 16 ms | 12032 KB |
1_077.txt | AC | 16 ms | 12032 KB |
1_078.txt | AC | 16 ms | 12032 KB |
1_079.txt | AC | 16 ms | 12032 KB |
1_080.txt | AC | 16 ms | 12032 KB |
1_081.txt | AC | 16 ms | 12032 KB |
1_082.txt | AC | 16 ms | 12032 KB |
1_083.txt | AC | 16 ms | 12032 KB |
1_084.txt | AC | 16 ms | 12032 KB |
1_085.txt | AC | 16 ms | 12032 KB |
1_086.txt | AC | 16 ms | 12032 KB |