Advertisement
BaoJIaoPisu

Untitled

Aug 19th, 2022
872
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.45 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. using ll = long long;
  6. using ld = long double;
  7. using ull = unsigned long long;
  8.  
  9. using pii = pair<int, int>;
  10. using pll = pair<ll, ll>;
  11. using pld = pair<ld, ld>;
  12.  
  13. #define fi first
  14. #define se second
  15. #define pb push_back
  16. #define pf push_front
  17. #define mp make_pair
  18. #define ins insert
  19. #define btpc __builtin_popcount
  20. #define btclz __builtin_clz
  21.  
  22. #define sz(x) (int)(x.size());
  23. #define all(x) x.begin(), x.end()
  24. #define debug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
  25.  
  26. mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  27.  
  28. int d4x[4] = {1, 0, -1, 0}; int d4y[4] = {0, 1, 0, -1};
  29. int d8x[8] = {0, 1, 1, 1, 0, -1, -1, -1};
  30. int d8y[8] = {1, 1, 0, -1, -1, -1, 0, 1};
  31.  
  32. template<class X, class Y>
  33.     bool minimize(X &x, const Y &y) {
  34.         if (x > y)
  35.         {
  36.             x = y;
  37.             return true;
  38.         }
  39.         return false;
  40.     }
  41. template<class X, class Y>
  42.     bool maximize(X &x, const Y &y) {
  43.         if (x < y)
  44.         {
  45.             x = y;
  46.             return true;
  47.         }
  48.         return false;
  49.     }
  50.  
  51. const int MOD = 1e9 + 7; //998244353
  52.  
  53. template<class X, class Y>
  54.     void add(X &x, const Y &y) {
  55.         x = (x + y);
  56.         if(x >= MOD) x -= MOD;
  57.     }
  58.  
  59. template<class X, class Y>
  60.     void sub(X &x, const Y &y) {
  61.         x = (x - y);
  62.         if(x < 0) x += MOD;
  63.     }
  64.  
  65. /* Author : Le Ngoc Bao Anh, 11A5, LQD High School for Gifted Student*/
  66.  
  67. const ll INF = 1e9;
  68. const int size = 40;
  69.  
  70. bool image[size + 1][size + 1];
  71. bool current[size + 1][size + 1];
  72.  
  73. string Encode(bool image[size + 1][size + 1], int number) {
  74.     string ans = "";
  75.  
  76.     bool found = false;
  77.     for(int i = 1; i <= size; i++) {
  78.         int cnt = 0;
  79.         for(int j = 1; j <= size; j++) {
  80.             if(image[i][j]) {
  81.                 int pos = j;
  82.                 for(int k = j; k <= size; k++) {
  83.                     if(image[i][k]) pos = k;
  84.                     else break;
  85.                 }
  86.  
  87.                 j = pos;
  88.                 ++cnt;
  89.             }
  90.         }
  91.  
  92.         if(cnt == 0) continue;
  93.  
  94.         if(!found) {
  95.             ans += (i + '0');
  96.             found = true;
  97.         }
  98.  
  99.         for(int j = 1; j <= size; j++) {
  100.             if(image[i][j]) {
  101.                 int pos = j;
  102.                 for(int k = j; k <= size; k++) {
  103.                     if(image[i][k]) pos = k;
  104.                     else break;
  105.                 }
  106.  
  107.                 ans += j + '0';
  108.                 ans += pos + '0';
  109.                 j = pos;
  110.             }
  111.         }
  112.     }
  113.  
  114.     ans += number + '0';
  115.     return ans;
  116. }
  117.  
  118. int Decode(string Encode) {
  119.     int sz = Encode.size();
  120.     int firstRow = Encode[0] - '0';
  121.     int number = Encode.back() - '0';
  122.     for(int i = 1; i <= size; i++) {
  123.         for(int j = 1; j <= size; j++) current[i][j] = 0;
  124.     }
  125.    
  126.     int row = firstRow - 1, lastR = 0;
  127.     for(int i = 1; i + 1 < sz; i += 2) {
  128.         int L = Encode[i] - '0';
  129.         int R = Encode[i + 1] - '0';
  130.         if(L <= lastR) row++;
  131.         lastR = R;
  132.         for(int j = L; j <= R; j++) current[row][j] = 1;
  133.     }
  134.  
  135.     return number;
  136. }
  137.  
  138. void solve() {
  139.     for(int i = 1; i <= size; i++) {
  140.         for(int j = 1; j <= size; j++) {
  141.             cin >> image[i][j];
  142.         }
  143.     }
  144.  
  145.     int number; cin >> number;
  146.     string Encoded = Encode(image, number);
  147.     number = Decode(Encoded);
  148.  
  149.     for(int i = 1; i <= size; i++) {
  150.         for(int j = 1; j <= size; j++) {
  151.             cout << current[i][j] << " ";
  152.         }
  153.         cout << endl;
  154.     }
  155. }
  156.  
  157. int main()
  158. {
  159.     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  160.     #ifndef ONLINE_JUDGE
  161.     freopen("input.txt", "r", stdin);
  162.     freopen("output.txt", "w", stdout);
  163.     #else
  164.     //online
  165.     #endif
  166.  
  167.     int tc = 1, ddd = 0;
  168.     // cin >> tc;
  169.     while(tc--) {
  170.         //ddd++;
  171.         //cout << "Case #" << ddd << ": ";
  172.         solve();
  173.     }
  174. }  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement