Submission #1108771

#TimeUsernameProblemLanguageResultExecution timeMemory
1108771TsaganaEnergetic turtle (IZhO11_turtle)C++17
10 / 100
673 ms146504 KiB
#include<bits/stdc++.h> #define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie(); #define all(x) x.begin(), x.end() #define lnl long long #define pq priority_queue #define eb emplace_back #define lb lower_bound #define ub upper_bound #define pb push_back #define pp pop_back #define F first #define S second using namespace std; struct row { int y[1001][21]; bool t[1001]; }; int antiloop = 0; int md; int n, m; int k, t; int a[30]; row X[1001]; map<pair<int, int>, bool> mp; void solve () { cin >> n >> m >> k >> t >> md; for (int i = 0; i < k; i++) { int x, y; cin >> x >> y; X[x].t[y] = 1; } for (int i = 0; i <= t; i++) X[0].y[0][i] = 0; X[0].y[0][0] = 1; queue<pair<int, int>> q; q.push({0, 0}); while (!q.empty()) { pair<int, int> p = q.front(); q.pop(); if (mp.find(p) != mp.end()) continue ; mp[p] = 1; if (p.F) { if (X[p.F].t[p.S]) { for (int i = 0; i < t; i++) { X[p.F].y[p.S][i+1] += X[p.F-1].y[p.S][i]; X[p.F].y[p.S][i+1] %= md; } } else { for (int i = 0; i <= t; i++) { X[p.F].y[p.S][i] += X[p.F-1].y[p.S][i]; X[p.F].y[p.S][i] %= md; } } } if (p.S) { if (X[p.F].t[p.S]) { for (int i = 0; i < t; i++) { X[p.F].y[p.S][i+1] += X[p.F].y[p.S-1][i]; X[p.F].y[p.S][i+1] %= md; } } else { for (int i = 0; i <= t; i++) { X[p.F].y[p.S][i] += X[p.F].y[p.S-1][i]; X[p.F].y[p.S][i] %= md; } } } if (p.F != n) q.push({p.F+1, p.S}); if (p.S != m) q.push({p.F, p.S+1}); // antiloop++; if (antiloop > 20) exit(0); // cout << p.F << ' ' << p.S << '\n'; // for (int i = 0; i <= t; i++) { // cout << X[p.F].y[p.S][i] << ' '; // } // cout << '\n'; } int ans = 0; for (int i = 0; i <= t; i++) { ans += X[n].y[m][i]; } cout << ans; } int main() {IOS solve(); return 0;}
#Verdict Execution timeMemoryGrader output
Fetching results...