Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
- // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx")
- #include <iostream>
- #include <vector>
- #include <cmath>
- #include <algorithm>
- #include <set>
- #include <map>
- #include <queue>
- #include <random>
- #include <chrono>
- #include <cassert>
- #include <sstream>
- #include <fstream>
- #include <iomanip>
- #include <tuple>
- #define fi first
- #define se second
- #define pb push_back
- #define ll long long
- #define ld long double
- #define hm unordered_map
- #define pii pair<int, int>
- #define sz(a) (int)a.size()
- #define all(a) a.begin(), a.end()
- #define cinv(v) for (auto& x: v) cin >> x
- #define fr(i, n) for (int i = 0; i < (n); ++i)
- #define fl(i, l, n) for (int i = (l); i < (n); ++i)
- #define int ll
- template <typename T1, typename T2> inline bool chkmin(T1 &x, const T2 &y) {if (x > y) {x = y; return 1;} return 0;}
- template <typename T1, typename T2> inline bool chkmax(T1 &x, const T2 &y) {if (x < y) {x = y; return 1;} return 0;}
- using namespace std;
- #ifdef LOCAL
- #define dbg(x) cerr << #x << " : " << x << endl
- #else
- #define dbg(x)
- #endif
- //tg: @runningcherry
- template <typename Collection> string Join (const Collection& col) {
- bool first = true;
- stringstream ss;
- for (const auto& x: col) {
- if (!first) ss << ", ";
- first = false;
- ss << x;
- }
- return ss.str ();
- }
- template <typename T1, typename T2> ostream& operator << (ostream& out, const pair<T1, T2>& v) {
- return out << '{' << v.fi << ", " << v.se << '}';
- }
- template<typename T> ostream& operator << (ostream& out, const vector<T>& v) {
- return out << '[' << Join (v) << ']';
- }
- template <typename T1, typename T2> ostream& operator << (ostream& out, const map<T1, T2>& v) {
- return out << '{' << Join (v) << '}';
- }
- template<typename T> ostream& operator << (ostream& out, const set<T>& v) {
- return out << '(' << Join (v) << ')';
- }
- template<typename T> ostream& operator << (ostream& out, const multiset<T>& v) {
- return out << '(' << Join (v) << ')';
- }
- template <typename T1, typename T2> istream& operator >> (istream& in, pair<T1, T2>& a) {
- return in >> a.fi >> a.se;
- }
- const ll inf = (ll) 2e9;
- const ll mod = (ll)1e9 + 7;
- const int maxn = 11;
- mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
- vector <pair <int, int>> d = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
- int goo[maxn][maxn], si = 5, sj = 5, dp[maxn][maxn];
- int corr (int i, int j) {
- return i >= 0 && j >= 0 && i < maxn && j < maxn;
- }
- int calc (vector <int> t) {
- for (auto& v: dp) for (auto& x: v) x = 0;
- queue <pair <int, int>> a;
- a.push ({si, sj});
- dp[si][sj] = goo[si][sj];
- pair <int, int> last;
- while (!a.empty ()) {
- auto ptt = a.front ();
- a.pop ();
- last = ptt;
- int i = ptt.first, j = ptt.second;
- for (auto& r: t) {
- auto x = d[r];
- int ii = i + x.first, jj = j + x.second;
- if (corr (ii, jj)) {
- chkmax (dp[ii][jj], dp[i][j] + goo[ii][jj]);
- a.push ({ii, jj});
- }
- }
- }
- return dp[last.first][last.second];
- }
- signed main () {
- ios_base::sync_with_stdio (false);
- cin.tie (nullptr);
- for (auto& v: goo) for (auto& x: v) cin >> x;
- vector <int> a = {calc ({0, 2}), calc ({0, 3}), calc ({1, 2}), calc ({1, 3})};
- sort (all (a));
- for (auto& x: a) cout << x << ' ';
- cout << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement