#include<bits/stdc++.h> using namespace std; #define FOR(i, a, b) for(int i = a; i <= b; i++) #define REP(i, a) FOR(i, 0, a - 1) #define ST first #define ND second #define V vector #define RS resize #define EB emplace_back #define ALL(a) a.begin(), a.end() #define S(a) (int)a.size() template<class T> void db(T a) { cerr << a; } template<class L, class R> void db(pair<L, R> a) { cerr << "(" << a.ST << ", " << a.ND << ")"; } void db(V<pair<int, int> > v) { cerr << "\n{\n"; REP(i, S(v)) cerr << " " << i << ": ", db(v[i]), cerr << "\n"; cerr << "}"; } template<class T> void db(V<T> v) { cerr << "{"; REP(i, S(v)) cerr << (i != 0 ? ", " : ""), db(v[i]); cerr << "}"; } template<class T> void dump(const char *s, T a) { cerr << s << ": "; db(a); cerr << "\n"; } template<class T, class... TS> void dump(const char *s, T a, TS... x) { while(*s != ',') cerr<< *s++; cerr << ": "; db(a); dump(s + 1, x...); } #ifdef DEBUG #define DB(...) dump(#__VA_ARGS__, __VA_ARGS__); #else #define DB(...) #endif using LL = long long; using PII = pair<int, int>; using VI = V<int>; using VLL = V<LL>; using VVI = V<VI>; using VPII = V<PII>; VPII data = { {0, 1}, {3, 4}, {5, 12}, {8, 15}, {20, 21}, {7, 24}, {12, 35}, {9, 40}, {28, 45}, {48, 55}, {33, 56}, {11, 60}, {16, 63}, {65, 72}, {36, 77}, {39, 80}, {13, 84}, {60, 91}, {20, 99}, {88, 105}, {15, 112}, {44, 117}, {119, 120}, {85, 132}, {51, 140}, {24, 143}, {17, 144} }; unsigned int X, Y, k; void remove_too_long(VPII &ang) { VPII copy; REP(i, S(ang)) if(ang[i].ST * ang[i].ST + ang[i].ND * ang[i].ND <= k * k && ang[i].ST <= X && ang[i].ND <= Y) copy.EB(ang[i]); ang = copy; } void add_swapped(VPII &ang) { VPII to_add; REP(i, S(ang)) to_add.EB(ang[i].ND, ang[i].ST); REP(i, S(to_add)) ang.EB(to_add[i]); } void add_reversed(VPII &ang) { VPII to_add; REP(i, S(ang)) { if(ang[i].ST != 0) to_add.EB(-ang[i].ST, ang[i].ND); if(ang[i].ND != 0) to_add.EB(ang[i].ST, -ang[i].ND); if(ang[i].ST != 0 && ang[i].ND != 0) to_add.EB(-ang[i].ST, -ang[i].ND); } REP(i, S(to_add)) ang.EB(to_add[i]); } void angle_sort(VPII &ang) { sort(ALL(ang), [](PII i, PII j) { REP(q, 2) { if(i.ND >= 0 && j.ND < 0) return (q == 0); swap(i, j); } return i.ST * j.ND - i.ND * j.ST > 0; }); } VPII angles; void construct_angles() { int size = 0; if(k <= 15) size = 3; else if(X <= 150 && Y <= 150) size = 27; else if(k <= 100) size = 17; angles = VPII(data.begin(), data.begin() + size); remove_too_long(angles); add_swapped(angles); add_reversed(angles); angle_sort(angles); } unsigned int ans = 0; void backtrack(int x = 0, int y = 0, int mx = 0, int my = 0, int Mx = 0, int My = 0, int pos = 0, int len = 0) { if(Mx - mx >= X) return; if(My - my >= Y) return; if(x == 0 && y == 0 && len != 0) { if(len > 2) ans += (X - (Mx - mx)) * (Y - (My - my)); return; } int _x, _y; while(pos < S(angles)) { _x = x + angles[pos].ST; _y = y + angles[pos].ND; backtrack(_x, _y, min(mx, _x), min(my, _y), max(Mx, _x), max(My, _y), ++pos, len + 1); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> X >> Y >> k; construct_angles(); backtrack(); cout << ans << "\n"; }
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 | #include<bits/stdc++.h> using namespace std; #define FOR(i, a, b) for(int i = a; i <= b; i++) #define REP(i, a) FOR(i, 0, a - 1) #define ST first #define ND second #define V vector #define RS resize #define EB emplace_back #define ALL(a) a.begin(), a.end() #define S(a) (int)a.size() template<class T> void db(T a) { cerr << a; } template<class L, class R> void db(pair<L, R> a) { cerr << "(" << a.ST << ", " << a.ND << ")"; } void db(V<pair<int, int> > v) { cerr << "\n{\n"; REP(i, S(v)) cerr << " " << i << ": ", db(v[i]), cerr << "\n"; cerr << "}"; } template<class T> void db(V<T> v) { cerr << "{"; REP(i, S(v)) cerr << (i != 0 ? ", " : ""), db(v[i]); cerr << "}"; } template<class T> void dump(const char *s, T a) { cerr << s << ": "; db(a); cerr << "\n"; } template<class T, class... TS> void dump(const char *s, T a, TS... x) { while(*s != ',') cerr<< *s++; cerr << ": "; db(a); dump(s + 1, x...); } #ifdef DEBUG #define DB(...) dump(#__VA_ARGS__, __VA_ARGS__); #else #define DB(...) #endif using LL = long long; using PII = pair<int, int>; using VI = V<int>; using VLL = V<LL>; using VVI = V<VI>; using VPII = V<PII>; VPII data = { {0, 1}, {3, 4}, {5, 12}, {8, 15}, {20, 21}, {7, 24}, {12, 35}, {9, 40}, {28, 45}, {48, 55}, {33, 56}, {11, 60}, {16, 63}, {65, 72}, {36, 77}, {39, 80}, {13, 84}, {60, 91}, {20, 99}, {88, 105}, {15, 112}, {44, 117}, {119, 120}, {85, 132}, {51, 140}, {24, 143}, {17, 144} }; unsigned int X, Y, k; void remove_too_long(VPII &ang) { VPII copy; REP(i, S(ang)) if(ang[i].ST * ang[i].ST + ang[i].ND * ang[i].ND <= k * k && ang[i].ST <= X && ang[i].ND <= Y) copy.EB(ang[i]); ang = copy; } void add_swapped(VPII &ang) { VPII to_add; REP(i, S(ang)) to_add.EB(ang[i].ND, ang[i].ST); REP(i, S(to_add)) ang.EB(to_add[i]); } void add_reversed(VPII &ang) { VPII to_add; REP(i, S(ang)) { if(ang[i].ST != 0) to_add.EB(-ang[i].ST, ang[i].ND); if(ang[i].ND != 0) to_add.EB(ang[i].ST, -ang[i].ND); if(ang[i].ST != 0 && ang[i].ND != 0) to_add.EB(-ang[i].ST, -ang[i].ND); } REP(i, S(to_add)) ang.EB(to_add[i]); } void angle_sort(VPII &ang) { sort(ALL(ang), [](PII i, PII j) { REP(q, 2) { if(i.ND >= 0 && j.ND < 0) return (q == 0); swap(i, j); } return i.ST * j.ND - i.ND * j.ST > 0; }); } VPII angles; void construct_angles() { int size = 0; if(k <= 15) size = 3; else if(X <= 150 && Y <= 150) size = 27; else if(k <= 100) size = 17; angles = VPII(data.begin(), data.begin() + size); remove_too_long(angles); add_swapped(angles); add_reversed(angles); angle_sort(angles); } unsigned int ans = 0; void backtrack(int x = 0, int y = 0, int mx = 0, int my = 0, int Mx = 0, int My = 0, int pos = 0, int len = 0) { if(Mx - mx >= X) return; if(My - my >= Y) return; if(x == 0 && y == 0 && len != 0) { if(len > 2) ans += (X - (Mx - mx)) * (Y - (My - my)); return; } int _x, _y; while(pos < S(angles)) { _x = x + angles[pos].ST; _y = y + angles[pos].ND; backtrack(_x, _y, min(mx, _x), min(my, _y), max(Mx, _x), max(My, _y), ++pos, len + 1); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> X >> Y >> k; construct_angles(); backtrack(); cout << ans << "\n"; } |