Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- --┬-- | | --┬-- | |
- | |\ | | | |
- | | \ | | -----> | |
- | | \ | | | |
- | | \ | | | |
- --┴-- | \| | └---- └----
- */
- //#define pragma
- #ifdef pragma
- #pragma GCC optimize("Ofast")
- #pragma GCC optimize("no-stack-protector")
- #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
- #pragma GCC optimize("unroll-loops")
- #pragma GCC diagnostic ignored "-Wunused-result"
- #endif // pragma
- #include<bits/stdc++.h>
- #include <ext/pb_ds/detail/standard_policies.hpp>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #define ll long long
- #define all(x) begin(x), end(x)
- #define pb push_back
- #define x first
- #define y second
- #define int long long
- #define zero(x) memset(x, 0, sizeof(x))
- using namespace std;
- using namespace __gnu_pbds;
- typedef vector<int> vi;
- typedef vector<bool> vb;
- typedef pair<int, int> pii;
- typedef long double ld;
- typedef vector<vi> matrix;
- typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
- const int INF = 1e9 + 7;
- const int MAXN = 1e5 + 7;
- const ld EPS = 1e-6;
- const ld PI = atan2(0, -1);
- void seriy() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- // cout << fixed << setprecision(10);
- #if _android
- freopen("input", "r", stdin);
- freopen("output", "w", stdout);
- #endif
- }
- signed main() {
- seriy();
- int n;
- cin >> n;
- char a[n][n];
- pii p[n][n];
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < n; j++) {
- cin >> a[i][j];
- }
- }
- int dp[n][n];
- memset(dp, INF, sizeof(dp));
- dp[0][0] = a[0][0] - '0';
- p[0][0] = {-1, -1};
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < n; j++) {
- if(i == 0 && j == 0) {
- continue;
- }
- if(i > 0) {
- dp[i][j] = dp[i - 1][j] + (a[i][j] - '0');
- p[i][j] = {i - 1, j};
- }
- else if(j > 0) {
- dp[i][j] = dp[i][j - 1] + (a[i][j] - '0');
- p[i][j] = {i, j - 1};
- }
- if(i > 0 && j > 0) {
- if(dp[i - 1][j] < dp[i][j - 1]) {
- dp[i][j] = dp[i - 1][j] + (a[i][j] - '0');
- p[i][j] = {i - 1, j};
- }
- else {
- dp[i][j] = dp[i][j - 1] + (a[i][j] - '0');
- p[i][j] = {i, j - 1};
- }
- }
- }
- }
- pii cur = {n - 1, n - 1};
- char ans[n][n];
- memset(ans, '.', sizeof(ans));
- while(cur.x != -1) {
- ans[cur.x][cur.y] = '#';
- cur = p[cur.x][cur.y];
- }
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < n; j++) {
- cout << ans[i][j];
- }
- cout << '\n';
- }
- // cout << dp[n - 1][n - 1];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement