답안 #248777

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
248777 2020-07-13T11:12:12 Z srvlt 힘 센 거북 (IZhO11_turtle) C++14
5 / 100
1 ms 640 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
template <typename T> using ord_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

constexpr int n0 = 3e5 + 123, k0 = 23;
int n, m, k, t, z, C[k0][k0], f[k0], cf[k0];
array <int, 2> p[k0];

int w(int x, int y, int x2, int y2) {
	if (x2 - x + y2 - y >= k0) assert(false);
	return C[x2 - x + y2 - y][x2 - x];
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> n >> m >> k >> t >> z;
	C[0][0] = 1 % z;
	for (int i = 1; i < k0; i++) {
		C[i][0] = 1 % z;
		for (int j = 1; j <= i; j++) {
			C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % z;
		}
	}
	for (int i = 0; i < k; i++)
		cin >> p[i][0] >> p[i][1];
	sort(p, p + k);
	for (int mask = 1; mask < (1 << k); mask++) {
		int bad = 0, res = 1 % z, last = -1;
		for (int i = 0; i < k; i++) {
			if (mask >> i & 1) {
				if (i > 0 && p[i][1] < p[i - 1][1]) {
					bad = 1;
					break;
				}
				if (i == 0) res = (ll)res * w(0, 0, p[i][0], p[i][1]) % z;
				else res = (ll)res * w(p[i - 1][0], p[i - 1][1], p[i][0], p[i][1]) % z;
				last = i;
			}
		}
		if (bad) continue;
		res = (ll)res * w(p[last][0], p[last][1], n, m) % z;
		int b = __builtin_popcount(mask);
		f[b] = (f[b] + res) % z;
	}
	int res = w(0, 0, n, m);
	for (int i = t + 1; i <= k; i++) {
		int cur = 0;
		for (int j = t + 1; j < i; j++)
			cur = (cur + (ll)C[i][j] * cf[j] % z) % z;
		cf[i] = (z - 1) - cur;
		res = (res + (ll)cf[i] * f[i] % z) % z;
	}
	cout << res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Runtime error 1 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)