Advertisement
GerONSo

Untitled

Sep 30th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. /*
  2. --┬-- | | --┬-- | |
  3. | |\ | | | |
  4. | | \ | | -----> | |
  5. | | \ | | | |
  6. | | \ | | | |
  7. --┴-- | \| | └---- └----
  8.  
  9. */
  10.  
  11. //#define pragma
  12.  
  13. #ifdef pragma
  14. #pragma GCC optimize("Ofast")
  15. #pragma GCC optimize("no-stack-protector")
  16. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  17. #pragma GCC optimize("unroll-loops")
  18. #pragma GCC diagnostic ignored "-Wunused-result"
  19. #endif // pragma
  20.  
  21. #include<bits/stdc++.h>
  22. #include <ext/pb_ds/detail/standard_policies.hpp>
  23. #include <ext/pb_ds/assoc_container.hpp>
  24. #include <ext/pb_ds/tree_policy.hpp>
  25.  
  26. #define ll long long
  27. #define all(x) begin(x), end(x)
  28. #define pb push_back
  29. #define x first
  30. #define y second
  31. #define int long long
  32. #define zero(x) memset(x, 0, sizeof(x))
  33.  
  34. using namespace std;
  35. using namespace __gnu_pbds;
  36.  
  37.  
  38. typedef vector<int> vi;
  39. typedef vector<bool> vb;
  40. typedef pair<int, int> pii;
  41. typedef long double ld;
  42. typedef vector<vi> matrix;
  43. typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
  44.  
  45. const int INF = 1e9 + 7;
  46. const int MAXN = 1e5 + 7;
  47. const ld EPS = 1e-6;
  48. const ld PI = atan2(0, -1);
  49.  
  50. void seriy() {
  51. ios::sync_with_stdio(0);
  52. cin.tie(0);
  53. cout.tie(0);
  54. // cout << fixed << setprecision(10);
  55. #if _android
  56. freopen("input", "r", stdin);
  57. freopen("output", "w", stdout);
  58. #endif
  59. }
  60.  
  61. signed main() {
  62. seriy();
  63. int n;
  64. cin >> n;
  65. char a[n][n];
  66. pii p[n][n];
  67. for(int i = 0; i < n; i++) {
  68. for(int j = 0; j < n; j++) {
  69. cin >> a[i][j];
  70. }
  71. }
  72. int dp[n][n];
  73. memset(dp, INF, sizeof(dp));
  74. dp[0][0] = a[0][0] - '0';
  75. p[0][0] = {-1, -1};
  76. for(int i = 0; i < n; i++) {
  77. for(int j = 0; j < n; j++) {
  78. if(i == 0 && j == 0) {
  79. continue;
  80. }
  81. if(i > 0) {
  82. dp[i][j] = dp[i - 1][j] + (a[i][j] - '0');
  83. p[i][j] = {i - 1, j};
  84. }
  85. else if(j > 0) {
  86. dp[i][j] = dp[i][j - 1] + (a[i][j] - '0');
  87. p[i][j] = {i, j - 1};
  88. }
  89. if(i > 0 && j > 0) {
  90. if(dp[i - 1][j] < dp[i][j - 1]) {
  91. dp[i][j] = dp[i - 1][j] + (a[i][j] - '0');
  92. p[i][j] = {i - 1, j};
  93. }
  94. else {
  95. dp[i][j] = dp[i][j - 1] + (a[i][j] - '0');
  96. p[i][j] = {i, j - 1};
  97. }
  98. }
  99. }
  100. }
  101. pii cur = {n - 1, n - 1};
  102. char ans[n][n];
  103. memset(ans, '.', sizeof(ans));
  104. while(cur.x != -1) {
  105. ans[cur.x][cur.y] = '#';
  106. cur = p[cur.x][cur.y];
  107. }
  108. for(int i = 0; i < n; i++) {
  109. for(int j = 0; j < n; j++) {
  110. cout << ans[i][j];
  111. }
  112. cout << '\n';
  113. }
  114. // cout << dp[n - 1][n - 1];
  115. return 0;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement