Advertisement
Korotkodul

крипто N1

Nov 9th, 2022 (edited)
700
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int, int>
  11. #define pb(x) push_back(x)
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v) {
  17.     for (auto x : v) cout << x << ' ';
  18.     cout << "\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v) {
  22.     for (auto x : v) cout << x << ' ';
  23.     cout << "\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v) {
  28.     for (auto x : v) cv(x);
  29.     cout << "\n";
  30. }
  31.  
  32. void cvb(vector <bool> v) {
  33.     for (bool x : v) cout << x << ' ';
  34.     cout << "\n";
  35. }
  36.  
  37. void cvs(vector <string>  v) {
  38.     for (auto a : v) {
  39.         cout << a << "\n";
  40.     }
  41. }
  42.  
  43. void cvp(vector <pii> a) {
  44.     for (auto p : a) {
  45.         cout << p.first << ' ' << p.second << "\n";
  46.     }
  47.     cout << "\n";
  48. }
  49.  
  50. bool sh = 0;
  51.  
  52. string to(int x) {
  53.     string r = "";
  54.     while (x > 0) {
  55.         r += x % 4 + '0';
  56.         x /= 4;
  57.     }
  58.     reverse(r.begin(), r.end());
  59.     while (r.size() < 16) {
  60.         r = '0' + r;
  61.     }
  62.     return r;
  63. }
  64.  
  65. bool ok(string s) {
  66.     int id = -1;
  67.     vector <vector <int> > a(4, vector <int> (4));
  68.     for (int i = 0; i < 4; ++i) {
  69.         for (int j = 0; j < 4; ++j) {
  70.             id++;
  71.             a[i][j] = s[id] - '0';
  72.         }
  73.     }
  74.     if (sh) {
  75.         cout << "a\n";
  76.         cvv(a);
  77.     }
  78.     for (int i = 0; i < 4; ++i) {
  79.         int t = 0;
  80.         for (int j = 0; j < 4; ++j) {
  81.             t += a[i][j];
  82.         }
  83.         if (t % 4 != 0) {
  84.             return 0;
  85.         }
  86.     }
  87.  
  88.     for (int j = 0; j < 4; ++j) {
  89.         int t = 0;
  90.         for (int i = 0; i < 4; ++i) {
  91.             t += a[i][j];
  92.         }
  93.         if (t % 4 != 0) {
  94.             return 0;
  95.         }
  96.     }
  97.     int t = 0;
  98.     for (int i = 0; i < 4; ++i) {
  99.         t += a[i][i];
  100.     }
  101.     if (t % 4 != 0) {
  102.         return 0;
  103.     }
  104.     for (int i = 0; i < 4; ++i) {
  105.         t += a[i][3 - i];
  106.     }
  107.     if (t % 4 != 0) {
  108.         return 0;
  109.     }
  110.     return 1;
  111. }
  112.  
  113.  
  114. int main() {
  115.     /*ios::sync_with_stdio(0);
  116.     cin.tie(0);
  117.     cout.tie(0);*/
  118.     ll ans = 0, til = pow(3, 16);
  119.     if (sh) {
  120.         string s;
  121.         cin >> s;
  122.         if (ok(s)) {
  123.             cout << "OK\n";
  124.         }
  125.         else {
  126.             cout << "NO\n";
  127.         }
  128.     }
  129.     for (int i = 0; i < til; ++i) {
  130.         string t = to(i);
  131.         if (ok(t)) {
  132.             ans++;
  133.             if (sh) {
  134.                 cout << "OK\n";
  135.             }
  136.             continue;
  137.         }
  138.         if (sh) {
  139.             cout << "NO\n";
  140.         }
  141.     }
  142.     cout << ans;
  143. }
  144.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement