Submission #874973

# Submission time Handle Problem Language Result Execution time Memory
874973 2023-11-18T11:19:19 Z SevakYegoryan Energetic turtle (IZhO11_turtle) C++17
40 / 100
1534 ms 262144 KB
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <iomanip>
#include <iterator>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <numeric>
#include <cassert>
#include <limits>
#include <climits>
#include <unordered_set>
#include <unordered_map>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define cdap(k) cout.setf(ios::fixed | ios::showpoint); cout.precision(k);
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb push_back
#define ff first
#define ss second
#define mkp make_pair
#define mkt make_tuple
#define pque priority_queue
const int INF = INT_MAX;
const long long LNF = LLONG_MAX;

const int N = 1007;
ll x[N], y[N];
ll n, m, k, t, z;
map<pair<ll, ll>, bool> mp;

ll dp[N][N][23];

void solve()
{
	ll i, j, p;
	ll ans = 0LL;

	cin >> n >> m >> k >> t >> z;
	for (i = 1; i <= k; i++) {
		cin >> x[i] >> y[i];
		mp[{x[i], y[i]}] = true;
	}

	dp[0][0][0] = 1;
	for (p = 0; p <= k; p++) {
		for (i = 0; i <= n; i++) {
			for (j = 0; j <= m; j++) {
				if (i == 0 && j == 0) continue;
				if (!mp[{i, j}]) {
					if (i > 0) dp[i][j][p] += dp[i - 1][j][p];
					if (j > 0) dp[i][j][p] += dp[i][j - 1][p];
					dp[i][j][p] %= z;
				}
				else {
					if (i > 0) dp[i][j][p + 1] += dp[i - 1][j][p];
					if (j > 0) dp[i][j][p + 1] += dp[i][j - 1][p];
					dp[i][j][p + 1] %= z;
				}
			}
		}
	}

	for (i = 0; i <= t; i++) {
		ans += dp[n][m][i];
		ans %= z;
	}

	cout << ans << "\n";
	return;
}

int main()
{
	fastIO;
	int mt = 1;
	//cin >> mt;
	while(mt--) {
		solve();
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 984 KB Output is correct
4 Correct 5 ms 1884 KB Output is correct
5 Correct 39 ms 8180 KB Output is correct
6 Correct 361 ms 63468 KB Output is correct
7 Correct 852 ms 101376 KB Output is correct
8 Correct 1534 ms 244668 KB Output is correct
9 Runtime error 577 ms 262144 KB Execution killed with signal 9
10 Runtime error 674 ms 262144 KB Execution killed with signal 9
11 Runtime error 1006 ms 262144 KB Execution killed with signal 9
12 Runtime error 985 ms 262144 KB Execution killed with signal 9
13 Runtime error 966 ms 262144 KB Execution killed with signal 9
14 Runtime error 1002 ms 262144 KB Execution killed with signal 9
15 Runtime error 994 ms 262144 KB Execution killed with signal 9
16 Runtime error 938 ms 262144 KB Execution killed with signal 9
17 Runtime error 1018 ms 262144 KB Execution killed with signal 9
18 Runtime error 947 ms 262144 KB Execution killed with signal 9
19 Runtime error 965 ms 262144 KB Execution killed with signal 9
20 Runtime error 916 ms 262144 KB Execution killed with signal 9