Submission #874973

#TimeUsernameProblemLanguageResultExecution timeMemory
874973SevakYegoryanEnergetic turtle (IZhO11_turtle)C++17
40 / 100
1534 ms262144 KiB
#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 timeMemoryGrader output
Fetching results...