結果

問題 No.767 配られたジャパリまん
ユーザー FF256grhyFF256grhy
提出日時 2018-12-15 12:10:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,164 ms / 2,000 ms
コード長 2,529 bytes
コンパイル時間 1,705 ms
コンパイル使用メモリ 176,348 KB
実行使用メモリ 178,748 KB
最終ジャッジ日時 2023-10-25 21:46:32
合計ジャッジ時間 4,911 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
8,092 KB
testcase_01 AC 9 ms
8,092 KB
testcase_02 AC 10 ms
8,092 KB
testcase_03 AC 9 ms
8,096 KB
testcase_04 AC 11 ms
8,264 KB
testcase_05 AC 74 ms
19,004 KB
testcase_06 AC 10 ms
8,092 KB
testcase_07 AC 10 ms
8,096 KB
testcase_08 AC 9 ms
8,092 KB
testcase_09 AC 11 ms
8,264 KB
testcase_10 AC 40 ms
14,908 KB
testcase_11 AC 11 ms
8,432 KB
testcase_12 AC 11 ms
8,432 KB
testcase_13 AC 39 ms
14,908 KB
testcase_14 AC 10 ms
8,264 KB
testcase_15 AC 10 ms
8,116 KB
testcase_16 AC 11 ms
8,432 KB
testcase_17 AC 10 ms
8,100 KB
testcase_18 AC 10 ms
8,116 KB
testcase_19 AC 14 ms
10,812 KB
testcase_20 AC 1,164 ms
178,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

#define bit(b, i) (((b) >> (i)) & 1)
#define bc __builtin_popcountll

const int M = 200000;
int h, w, k, x[20], y[20];
LL f[M + 1], fi[M + 1], s[1 << 20][21], MOD = 1e8 + 7;

int main() {
	cin >> h >> w >> k;
	inc(i, k) { cin >> x[i] >> y[i]; }
	
	f[0] = 1;
	inc1(i, M) { f[i] = f[i - 1] * i % MOD; }
	fi[M] = 56264037;
	dec(i, M) { fi[i] = fi[i + 1] * (i + 1) % MOD; }
	
	inc(b, 1 << k) {
		vector<pair<int, int>> v;
		v.EB(0, 0);
		v.EB(h, w);
		inc(i, k) { if(bit(b, i)) { v.EB(x[i], y[i]); } }
		sort(ALL(v));
		
		int D = bc(b);
		s[b][D] = (D % 2 == 0 ? +1 : MOD - 1);
		inc(i, v.size() - 1) {
			int X = v[i + 1].FI - v[i].FI;
			int Y = v[i + 1].SE - v[i].SE;
			(s[b][D] *= (Y < 0 ? 0 : fi[X] * fi[Y] % MOD * f[X + Y] % MOD)) %= MOD;
		}
		
		
		inc(i, k) { if(bit(b, i) == 0) { continue; }
		inc(j, D) {
			s[b][j] += s[b ^ (1 << i)][j];
		}
		}
		inc(j, D) { s[b][j] %= MOD; }
		
		LL ans = 0;
		incII(j, 0, D) { ans += s[b][j] * fi[D - j]; }
		
		cout << ans % MOD << "\n";
	}
	
	return 0;
}
0