Advertisement
aayyk

Untitled

Aug 16th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.74 KB | None | 0 0
  1. #ifdef LOCAL
  2. #include "debug.h"
  3. #else
  4. #include <bits/stdc++.h>
  5. #define debug(x...)
  6. #endif
  7.  
  8. #define int ll
  9. //#pragma GCC optimize("Ofast")
  10.  
  11. using namespace std;
  12. typedef long long ll;
  13. typedef long double ld;
  14. typedef pair <int, int> pii;
  15. #define sz(x) int((x).size())
  16.  
  17. #ifdef ONLINE_JUDGE
  18. mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  19. #else
  20. mt19937 rng(1000 - 7);
  21. #endif
  22.  
  23. const int N = 3e3 + 10;
  24. const int M = 1e3 + 10;
  25. const int MOD = 998244353;
  26. //const int MOD = 1e9 + 7;
  27. const ld eps = 1e-6;
  28. const pii dir[] = { { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 } };
  29.  
  30.  
  31.  
  32. signed main() {
  33. #ifdef LOCAL
  34.     //freopen("input.txt", "r", stdin);
  35.     //freopen("output.txt", "w", stdout);
  36. #endif
  37.     cout << fixed << setprecision(9);
  38.     //ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  39.  
  40.     int n;
  41.     cin >> n;
  42.  
  43.     int a[n + 1][n + 1];
  44.  
  45.     for (int i = 0; i < n; i++) {
  46.         a[0][i] = i;
  47.     }
  48.     for (int i = 1; i < n; i++) {
  49.         a[i][n - 1] = a[i - 1][n - 1] + 1;
  50.     }
  51.  
  52.     for (int d = 1; d < n + n - 1; d++) {
  53.         for (int i = 1, j = d - 1; j >= 0; i++, j--) {
  54.             if (j + 1 < n)
  55.                 a[i][j] = a[i - 1][j + 1] + 1;
  56.         }
  57.     }
  58.  
  59.     for (int i = 0; i < n; i++) {
  60.         for (int j = 0; j < n; j++) {
  61.             cout << (1LL << a[i][j]) << " ";
  62.         }
  63.         cout << "\n";
  64.     }
  65.  
  66.     int up[n][n];
  67.     up[0][0] = 1;
  68.  
  69.     for (int i = 0; i < n; i++) {
  70.         for (int j = 0; j < n; j++) {
  71.             if (i + j == 0) {
  72.                 continue;
  73.             }
  74.  
  75.             if (j) {
  76.                 up[i][j] = up[i][j - 1] + (1LL << a[i][j]);
  77.             }
  78.             else {
  79.                 up[i][j] = up[i - 1][j] + (1LL << a[i][j]);
  80.             }
  81.         }
  82.     }
  83.  
  84.     debug(up[n - 1][n - 1]);
  85.  
  86.     int q;
  87.     cin >> q;
  88.  
  89.     while (q--) {
  90.         int x;
  91.         cin >> x;
  92.  
  93.         int i = n - 1, j = n - 1;
  94.         vector <pii> ans;
  95.         ans.push_back({ n - 1, n - 1 });
  96.  
  97.         while (!(i == 0 && j == 0)) {
  98.             x -= (1LL << a[i][j]);
  99.  
  100.             if (i == 0) {
  101.                 ans.push_back({ i, j - 1 });
  102.                 j--;
  103.             }
  104.             else if (j == 0) {
  105.                 ans.push_back({ i - 1, j });
  106.                 i--;
  107.             }
  108.             else {
  109.                 if (x > up[i - 1][j]) {
  110.                     ans.push_back({ i, j - 1 });
  111.                     j--;
  112.                 }
  113.                 else {
  114.                     ans.push_back({ i - 1, j });
  115.                     i--;
  116.                 }
  117.             }
  118.         }
  119.  
  120.         reverse(ans.begin(), ans.end());
  121.         for (auto [x, y] : ans) {
  122.             cout << x + 1 << " " << y + 1 << "\n";
  123.         }
  124.     }
  125.  
  126.     return 0;
  127. }
  128.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement