This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#pragma GCC optimize("O3","unroll-loops")
#pragma GCC target("avx2","popcnt","sse4","abm")
using namespace std;
#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
using ll = long long;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MXN = 5005, MXM = 55;
int n, m, d;
bitset<MXN> brd[MXM][MXM], b[MXM];
int SOLVE(int X, int Y) {
FOR(i, 0, d) b[i].reset();
int ans = INT_MAX, pre = d - 1;
FOR(r, 0, d) {
FOR(i, 0, pre + 1) b[i] |= brd[(X + r) % d][(Y + i) % d];
bitset<MXN> now;
now.reset();
int cnt = 0;
while (cnt < d && now.count() != n + m) {
now |= b[cnt];
cnt++;
}
if (now.count() == n + m) {
ans = min(ans, (r + 1) * cnt);
pre = cnt;
}
}
return ans;
}
void miku() {
int x, y;
cin >> n >> m >> d;
FOR(i, 0, n) {
cin >> x >> y;
brd[x][y][i] = true;
}
FOR(i, 0, m) {
cin >> x >> y;
FOR(j, 0, d) {
brd[x][j][i + n] = true;
brd[j][y][i + n] = true;
}
}
int ans = INT_MAX;
FOR(i, 0, d) FOR(j, 0, d) ans = min(ans, SOLVE(i, j));
cout << ans << '\n';
}
int32_t main() {
cin.tie(0) -> sync_with_stdio(false);
cin.exceptions(cin.failbit);
miku();
return 0;
}
Compilation message (stderr)
garden.cpp: In function 'int SOLVE(int, int)':
garden.cpp:36:39: warning: comparison of integer expressions of different signedness: 'std::size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
36 | while (cnt < d && now.count() != n + m) {
| ~~~~~~~~~~~~^~~~~~~~
garden.cpp:40:25: warning: comparison of integer expressions of different signedness: 'std::size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
40 | if (now.count() == n + m) {
| ~~~~~~~~~~~~^~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |