#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef long double LD; typedef pair < int, int > PII; typedef pair < LL, LL > PLL; typedef pair < LD, LD > PDD; #define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() template < typename _T > inline void _DBG(const char *s, _T x) { cerr << s << " = " << x << "\n"; } template < typename _T, typename... args > void _DBG(const char *s, _T x, args... a) { while(*s != ',') cerr << *s++; cerr << " = " << x << ','; _DBG(s + 1, a...); } #ifdef LOCAL #define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__) #define __gcd gcd #else #define DBG(...) (__VA_ARGS__) #define cerr if(0) cout #endif // ********************** CODE ********************** // typedef int T; typedef unsigned int UI; struct point { T x, y; point() {} point(T _x, T _y) : x(_x), y(_y) {} point(pair < T, T > p) : x(p.first), y(p.second) {} point operator+(point p) { return point(x + p.x, y + p.y); } point operator-(point p) { return point(x - p.x, y - p.y); } bool operator<(const point &p) const { return make_pair(x, y) < make_pair(p.x, p.y); } T norm() { return x * x + y * y; } T len() { return sqrt(norm()); } void print() { cout << x << " " << y; } void print(int prec) { cout << fixed << setprecision(prec) << x << " " << y; } void println() { cout << x << " " << y << "\n"; } void println(int prec) { cout << fixed << setprecision(prec) << x << " " << y << "\n"; } }; int x, y, k; vector < pair < point, int > > prop; void preprocessing() { for(int i = 1; i <= k; i++) { for(int j1 = -i; j1 <= i; j1++) { for(int j2 = -i; j2 <= i; j2++) { if(j1 * j1 + j2 * j2 == i * i && __gcd(abs(j1), abs(j2)) == 1) { prop.push_back({{j1, j2}, i}); } } } } } namespace subtaskA { void solve() { int n = sz(prop); UI ans = 0; for(int m = 1; m < (1 << n); m++) { int sx = 0, sy = 0, mx = 0, my = 0, cnt = 0; for(int i = 0; i < n; i++) { if((m >> i) & 1) { point p = prop[i].first; sx += p.x, sy += p.y; if(p.x > 0) mx += p.x; if(p.y > 0) my += p.y; cnt++; } } if(sx != 0 || sy != 0) { continue; } if(0 < mx && mx <= x && 0 < my && my <= y && cnt > 2) { UI ax = x - mx; UI ay = y - my; ans += ax * ay; } } cout << ans << "\n"; } } namespace subtaskB { const int N = 155; UI dp[N][3 * N][N]; UI res[N][N][2 * N]; bool mem[2 * N][2 * N]; vector < point > vec; void solve() { for(auto &p: prop) { if(p.first.x > 0 || (p.first.x == 0 && p.first.y > 0)) { vec.push_back(p.first); } } sort(all(vec), [](const point &p1, const point &p2){ return p1.y > p2.y; }); dp[0][N][0] = 1; mem[0][0] = true; for(auto p: vec) { if(p.y >= 0) mem[p.x][p.y] = true; for(int i = x - 1; i >= 0; i--) { for(int j = 2 * y; j >= -y; j--) { for(int l = 0; l < y; l++) { if(i - p.x >= 0 && 2 * y >= j - p.y && j - p.y >= -y && (p.y < 0 ? l + p.y : l) >= 0) dp[i][j + N][l] += dp[i - p.x][j - p.y + N][p.y < 0 ? l + p.y : l]; } } } } UI ans = 0; for(int i = 0; i < x; i++) { for(int j = 0; j < y; j++) { for(int z = -j; z <= j; z++) { for(int l1 = 0; l1 + z <= j; l1++) { int l2 = j - l1 - z; res[i][j][z + N] += dp[i][z + N][l1] * dp[i][z + N][l2]; } if(j == abs(z) && mem[i][j]) { if(i != 0 || z != -1) res[i][j][z + N]--; } UI ax = x - i, ay = y - j; ans += res[i][j][z + N] * ax * ay; } } } cout << ans << "\n"; } } namespace subtaskC { void solve() { } } namespace subtaskD { void solve() { } } int main() { _upgrade cin >> x >> y >> k; preprocessing(); if(k <= 15) { subtaskA::solve(); } else if(max(x, y) <= 150) { subtaskB::solve(); } else if(2000 <= min(x, y) && max(x, y) <= 2400 && k <= 100) { subtaskC::solve(); } else { subtaskD::solve(); } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef long double LD; typedef pair < int, int > PII; typedef pair < LL, LL > PLL; typedef pair < LD, LD > PDD; #define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() template < typename _T > inline void _DBG(const char *s, _T x) { cerr << s << " = " << x << "\n"; } template < typename _T, typename... args > void _DBG(const char *s, _T x, args... a) { while(*s != ',') cerr << *s++; cerr << " = " << x << ','; _DBG(s + 1, a...); } #ifdef LOCAL #define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__) #define __gcd gcd #else #define DBG(...) (__VA_ARGS__) #define cerr if(0) cout #endif // ********************** CODE ********************** // typedef int T; typedef unsigned int UI; struct point { T x, y; point() {} point(T _x, T _y) : x(_x), y(_y) {} point(pair < T, T > p) : x(p.first), y(p.second) {} point operator+(point p) { return point(x + p.x, y + p.y); } point operator-(point p) { return point(x - p.x, y - p.y); } bool operator<(const point &p) const { return make_pair(x, y) < make_pair(p.x, p.y); } T norm() { return x * x + y * y; } T len() { return sqrt(norm()); } void print() { cout << x << " " << y; } void print(int prec) { cout << fixed << setprecision(prec) << x << " " << y; } void println() { cout << x << " " << y << "\n"; } void println(int prec) { cout << fixed << setprecision(prec) << x << " " << y << "\n"; } }; int x, y, k; vector < pair < point, int > > prop; void preprocessing() { for(int i = 1; i <= k; i++) { for(int j1 = -i; j1 <= i; j1++) { for(int j2 = -i; j2 <= i; j2++) { if(j1 * j1 + j2 * j2 == i * i && __gcd(abs(j1), abs(j2)) == 1) { prop.push_back({{j1, j2}, i}); } } } } } namespace subtaskA { void solve() { int n = sz(prop); UI ans = 0; for(int m = 1; m < (1 << n); m++) { int sx = 0, sy = 0, mx = 0, my = 0, cnt = 0; for(int i = 0; i < n; i++) { if((m >> i) & 1) { point p = prop[i].first; sx += p.x, sy += p.y; if(p.x > 0) mx += p.x; if(p.y > 0) my += p.y; cnt++; } } if(sx != 0 || sy != 0) { continue; } if(0 < mx && mx <= x && 0 < my && my <= y && cnt > 2) { UI ax = x - mx; UI ay = y - my; ans += ax * ay; } } cout << ans << "\n"; } } namespace subtaskB { const int N = 155; UI dp[N][3 * N][N]; UI res[N][N][2 * N]; bool mem[2 * N][2 * N]; vector < point > vec; void solve() { for(auto &p: prop) { if(p.first.x > 0 || (p.first.x == 0 && p.first.y > 0)) { vec.push_back(p.first); } } sort(all(vec), [](const point &p1, const point &p2){ return p1.y > p2.y; }); dp[0][N][0] = 1; mem[0][0] = true; for(auto p: vec) { if(p.y >= 0) mem[p.x][p.y] = true; for(int i = x - 1; i >= 0; i--) { for(int j = 2 * y; j >= -y; j--) { for(int l = 0; l < y; l++) { if(i - p.x >= 0 && 2 * y >= j - p.y && j - p.y >= -y && (p.y < 0 ? l + p.y : l) >= 0) dp[i][j + N][l] += dp[i - p.x][j - p.y + N][p.y < 0 ? l + p.y : l]; } } } } UI ans = 0; for(int i = 0; i < x; i++) { for(int j = 0; j < y; j++) { for(int z = -j; z <= j; z++) { for(int l1 = 0; l1 + z <= j; l1++) { int l2 = j - l1 - z; res[i][j][z + N] += dp[i][z + N][l1] * dp[i][z + N][l2]; } if(j == abs(z) && mem[i][j]) { if(i != 0 || z != -1) res[i][j][z + N]--; } UI ax = x - i, ay = y - j; ans += res[i][j][z + N] * ax * ay; } } } cout << ans << "\n"; } } namespace subtaskC { void solve() { } } namespace subtaskD { void solve() { } } int main() { _upgrade cin >> x >> y >> k; preprocessing(); if(k <= 15) { subtaskA::solve(); } else if(max(x, y) <= 150) { subtaskB::solve(); } else if(2000 <= min(x, y) && max(x, y) <= 2400 && k <= 100) { subtaskC::solve(); } else { subtaskD::solve(); } return 0; } |