Submission #19263

# Submission time Handle Problem Language Result Execution time Memory
19263 2016-02-23T13:49:36 Z kaTkaHr 흑백 (kriii4_G) C++14
100 / 100
1559 ms 1184 KB
#include <stdio.h>
#include<vector>
#include <algorithm>
#include <map>

using namespace std;

typedef long long ll;

const int MX = 3005, MM = 1000000007;

ll pw(ll A, ll B){
    ll R = 1;
    while(B){
        if( B&1 ) R = R * A % MM;
        A = A * A % MM; B /= 2;
    }
    return R;
}


ll rv(ll A){ return pw(A, MM-2); }

struct frac{
    ll A, B;
		frac(ll A):A(A), B(1){}
    frac(ll a, ll b){
        A = (a%MM+MM) % MM;
        B = (b%MM+MM) % MM;
    }
    frac(){A = 0, B = 1;}
    frac operator+ (const frac &l)const{
        return frac((A * l.B + B * l.A) % MM, B * l.B % MM);
    }
    frac operator*(const frac &l)const{
        return frac(A*l.A % MM, B*l.B % MM);
    }
    frac operator/(const frac &l)const{
        return frac(A*l.B % MM, B*l.A % MM);
    }
    frac operator- (const frac &l)const{
        return frac((A*l.B - B*l.A%MM + MM) % MM, B*l.B % MM);
    }
    ll v(){ return A * rv(B) % MM; }
};

frac pw(frac A, ll B){
    frac R = 1;
    while(B){
        if( B&1 ) R = R * A;
        A = A * A; B /= 2;
    }
    return R;
}

frac F[MX], _5[MX];

int main()
{
	F[0] = 1; _5[0] = frac(1, 1);
	for(int i = 1; i <= 1000; i++) F[i] = F[i-1] * i, _5[i] = _5[i-1] * frac(1, 2);
	int H, W;
	scanf("%d%d", &H, &W);
	frac A = 0, B = 0, C = 0;
	for(int i = 1; i <= W; i++){
		for(int j = 1; j <= W-i; j++){
			int k = W-i-j;
			A = A + F[W] / F[i] / F[j] / F[k] * (
				pw(_5[i] + _5[j] + 1, H) 
				- pw(_5[i] + 1, H) 
				- pw(_5[j] + 1, H) 
				+ 1
			);
		}
	}
	
	for(int i = 1; i <= W; i++){
		for(int j = 1; j <= W-i; j++){
			int k = W-i-j;
			B = B + F[W] / F[i] / F[j] / F[k] * (
				pw(_5[i] + _5[j] + _5[i+j] + 1, H) 
				- pw(_5[i] + _5[j] + 1, H) 
			);
		}
	}
	for(int i = 1; i <= H; i++){
		for(int j = 1; j <= H-i; j++){
			int k = H-i-j;
			C = C + F[H] / F[i] / F[j] / F[k] * (
				pw(_5[i] + _5[j] + _5[i+j] + 1, W) 
				- pw(_5[i] + _5[j] + 1, W) 
			);
		}
	}
	frac ans = B + C + A;
	if( ans.A == 0 && ans.B == 0 ) for(;;);
	printf("%lld\n", ans.v());
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1184 KB Output is correct
2 Correct 0 ms 1184 KB Output is correct
3 Correct 0 ms 1184 KB Output is correct
4 Correct 0 ms 1184 KB Output is correct
5 Correct 0 ms 1184 KB Output is correct
6 Correct 0 ms 1184 KB Output is correct
7 Correct 0 ms 1184 KB Output is correct
8 Correct 0 ms 1184 KB Output is correct
9 Correct 0 ms 1184 KB Output is correct
10 Correct 0 ms 1184 KB Output is correct
11 Correct 0 ms 1184 KB Output is correct
12 Correct 0 ms 1184 KB Output is correct
13 Correct 0 ms 1184 KB Output is correct
14 Correct 0 ms 1184 KB Output is correct
15 Correct 0 ms 1184 KB Output is correct
16 Correct 0 ms 1184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 278 ms 1184 KB Output is correct
2 Correct 100 ms 1184 KB Output is correct
3 Correct 741 ms 1184 KB Output is correct
4 Correct 996 ms 1184 KB Output is correct
5 Correct 433 ms 1184 KB Output is correct
6 Correct 500 ms 1184 KB Output is correct
7 Correct 794 ms 1184 KB Output is correct
8 Correct 107 ms 1184 KB Output is correct
9 Correct 568 ms 1184 KB Output is correct
10 Correct 873 ms 1184 KB Output is correct
11 Correct 661 ms 1184 KB Output is correct
12 Correct 1087 ms 1184 KB Output is correct
13 Correct 217 ms 1184 KB Output is correct
14 Correct 679 ms 1184 KB Output is correct
15 Correct 735 ms 1184 KB Output is correct
16 Correct 221 ms 1184 KB Output is correct
17 Correct 271 ms 1184 KB Output is correct
18 Correct 224 ms 1184 KB Output is correct
19 Correct 445 ms 1184 KB Output is correct
20 Correct 119 ms 1184 KB Output is correct
21 Correct 1528 ms 1184 KB Output is correct
22 Correct 1486 ms 1184 KB Output is correct
23 Correct 1454 ms 1184 KB Output is correct
24 Correct 1559 ms 1184 KB Output is correct