Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int, int>
- #define pb(x) push_back(x)
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvl(vector <ll> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvv(vector <vector <int> > &v) {
- for (auto x : v) cv(x);
- cout << "\n";
- }
- void cvb(vector <bool> v) {
- for (bool x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvs(vector <string> v) {
- for (auto a : v) {
- cout << a << "\n";
- }
- }
- void cvp(vector <pii> a) {
- for (auto p : a) {
- cout << p.first << ' ' << p.second << "\n";
- }
- cout << "\n";
- }
- bool sh = 0;
- string to(int x) {
- string r = "";
- while (x > 0) {
- r += x % 4 + '0';
- x /= 4;
- }
- reverse(r.begin(), r.end());
- while (r.size() < 16) {
- r = '0' + r;
- }
- return r;
- }
- bool ok(string s) {
- int id = -1;
- vector <vector <int> > a(4, vector <int> (4));
- for (int i = 0; i < 4; ++i) {
- for (int j = 0; j < 4; ++j) {
- id++;
- a[i][j] = s[id] - '0';
- }
- }
- if (sh) {
- cout << "a\n";
- cvv(a);
- }
- for (int i = 0; i < 4; ++i) {
- int t = 0;
- for (int j = 0; j < 4; ++j) {
- t += a[i][j];
- }
- if (t % 4 != 0) {
- return 0;
- }
- }
- for (int j = 0; j < 4; ++j) {
- int t = 0;
- for (int i = 0; i < 4; ++i) {
- t += a[i][j];
- }
- if (t % 4 != 0) {
- return 0;
- }
- }
- int t = 0;
- for (int i = 0; i < 4; ++i) {
- t += a[i][i];
- }
- if (t % 4 != 0) {
- return 0;
- }
- for (int i = 0; i < 4; ++i) {
- t += a[i][3 - i];
- }
- if (t % 4 != 0) {
- return 0;
- }
- return 1;
- }
- int main() {
- /*ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);*/
- ll ans = 0, til = pow(3, 16);
- if (sh) {
- string s;
- cin >> s;
- if (ok(s)) {
- cout << "OK\n";
- }
- else {
- cout << "NO\n";
- }
- }
- for (int i = 0; i < til; ++i) {
- string t = to(i);
- if (ok(t)) {
- ans++;
- if (sh) {
- cout << "OK\n";
- }
- continue;
- }
- if (sh) {
- cout << "NO\n";
- }
- }
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement