| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #include "testlib.h" |
| #include <bits/stdc++.h> |
| using namespace std; |
|
|
| struct CellHash { |
| size_t operator()(const pair<long long,long long>& p) const noexcept { |
| uint64_t x = static_cast<uint64_t>(p.first); |
| uint64_t y = static_cast<uint64_t>(p.second); |
| |
| x ^= y + 0x9e3779b97f4a7c15ULL + (x<<6) + (x>>2); |
| x ^= x >> 30; x *= 0xbf58476d1ce4e5b9ULL; |
| x ^= x >> 27; x *= 0x94d049bb133111ebULL; |
| x ^= x >> 31; |
| return static_cast<size_t>(x); |
| } |
| }; |
|
|
| static inline pair<long long,long long> rot90cw(long long x, long long y, int r) { |
| switch (r & 3) { |
| case 0: return { x, y}; |
| case 1: return { y, -x}; |
| case 2: return {-x, -y}; |
| default: return {-y, x}; |
| } |
| } |
|
|
| int main(int argc, char* argv[]) { |
| registerTestlibCmd(argc, argv); |
|
|
| |
| const int n = inf.readInt(100, 10000, "n"); |
|
|
| vector<vector<pair<long long,long long>>> shapes(n); |
| long long totalCells = 0; |
|
|
| for (int i = 0; i < n; ++i) { |
| int k = inf.readInt(1, 10, "k_i"); |
| shapes[i].reserve(k); |
| for (int j = 0; j < k; ++j) { |
| long long x = inf.readLong(numeric_limits<long long>::min()/4, |
| numeric_limits<long long>::max()/4, "x_ij"); |
| long long y = inf.readLong(numeric_limits<long long>::min()/4, |
| numeric_limits<long long>::max()/4, "y_ij"); |
| shapes[i].push_back({x, y}); |
| } |
| totalCells += k; |
| } |
|
|
| |
| |
| long long W = ouf.readLong(1, (long long)4e12, "W"); |
| long long H = ouf.readLong(1, (long long)4e12, "H"); |
|
|
| struct Place { long long X, Y; int R; int F; }; |
| vector<Place> place(n); |
| for (int i = 0; i < n; ++i) { |
| long long X = ouf.readLong(-(long long)4e12, (long long)4e12, "X_i"); |
| long long Y = ouf.readLong(-(long long)4e12, (long long)4e12, "Y_i"); |
| int R = ouf.readInt(0, 3, "R_i"); |
| int F = ouf.readInt(0, 1, "F_i"); |
| place[i] = {X, Y, R, F}; |
| } |
|
|
| if (!ouf.seekEof()) { |
| quitf(_pe, "Extra data after expected %d placement lines", n); |
| } |
|
|
| |
| unordered_set<pair<long long,long long>, CellHash> occ; |
| occ.reserve(static_cast<size_t>(max<long long>(16, totalCells * 2))); |
|
|
| auto inBounds = [&](long long x, long long y) -> bool { |
| return x >= 0 && y >= 0 && x < W && y < H; |
| }; |
|
|
| for (int i = 0; i < n; ++i) { |
| const auto [X, Y, R, F] = place[i]; |
| for (const auto& c : shapes[i]) { |
| long long sx = c.first, sy = c.second; |
|
|
| |
| long long rx = (F == 1 ? -sx : sx); |
| long long ry = sy; |
|
|
| |
| auto [qx, qy] = rot90cw(rx, ry, R); |
|
|
| |
| long long gx, gy; |
| if (__builtin_add_overflow(qx, X, &gx) || |
| __builtin_add_overflow(qy, Y, &gy)) { |
| quitf(_wa, "Overflow after transforming piece %d", i+1); |
| } |
|
|
| if (!inBounds(gx, gy)) { |
| quitf(_wa, |
| "Out of bounds: piece %d cell -> (%lld,%lld) not in [0,%lld)×[0,%lld)", |
| i+1, gx, gy, W, H); |
| } |
|
|
| auto ins = occ.insert({gx, gy}); |
| if (!ins.second) { |
| quitf(_wa, "Overlap at cell (%lld,%lld)", gx, gy); |
| } |
| } |
| } |
|
|
| |
| |
| __int128 area128 = (__int128)W * (__int128)H; |
| if (area128 <= 0) quitf(_wa, "Non-positive area (W*H)"); |
| long long area; |
| if (area128 > numeric_limits<long long>::max()) |
| quitf(_wa, "Area overflow: W*H exceeds 64-bit"); |
| area = (long long)area128; |
|
|
| double score = (double) totalCells / (double) area; |
| |
| quitp(score, "Ratio: %.9f (cells=%lld, W=%lld, H=%lld, area=%lld)", |
| score, totalCells, W, H, area); |
| } |
|
|