제출 #501205

#제출 시각아이디문제언어결과실행 시간메모리
501205dxz05Chessboard (IZhO18_chessboard)C++14
16 / 100
34 ms4152 KiB
#pragma GCC optimize("Ofast,O2,O3,unroll-loops") #pragma GCC target("avx2") #include <bits/stdc++.h> using namespace std; void debug_out() { cerr << endl; } template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << "[" << H << "]"; debug_out(T...); } #ifdef dddxxz #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif #define SZ(s) ((int)s.size()) #define all(x) (x).begin(), (x).end() #define lla(x) (x).rbegin(), (x).rend() clock_t startTime; double getCurrentTime() { return (double) (clock() - startTime) / CLOCKS_PER_SEC; } #define MP make_pair typedef long long ll; mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const double eps = 0.000001; const int MOD = 998244353; const int INF = 1000000101; const long long LLINF = 1223372000000000555; const int N = 2e6 + 3e2; const int M = 222; #define rect pair<pair<ll,ll>,pair<ll,ll>> #define x1 first.first #define y1 first.second #define x2 second.first #define y2 second.second void solve(int TC) { int n, k; cin >> n >> k; vector<rect> rectangles(k); for (auto &r : rectangles){ cin >> r.x1 >> r.y1 >> r.x2 >> r.y2; } vector<ll> divisors; for (int d = 1; d < n; d++){ if (n % d == 0) divisors.push_back(d); } ll ans = 1ll * n * n; for (ll d : divisors){ /// (1, 1) = black ll cost = ((n / d) * (n / d) + 1) / 2 * d * d; for (auto r : rectangles){ ll i1 = (r.x1 + d - 2) / d + 1; ll j1 = (r.y1 + d - 2) / d + 1; ll i2 = r.x2 / d; ll j2 = r.y2 / d; ll id = i2 - i1 + 1, jd = j2 - j1 + 1; debug(i1, j1, i2, j2, id, jd); if (id < 0 || jd < 0){ ll S = (r.x2 - r.x1 + 1) * (r.y2 - r.y1 + 1); if ((i1 + j1) % 2 == 0) cost += S; else cost -= S; continue; } ll white = 0; white += (id * jd / 2) * d * d; if ((id * jd) % 2 == 1){ if ((i1 + j1) % 2 == 1) white += d * d; } ll h = (i1 - 1) * d - r.x1 + 1; h = max(h, 0ll); white += jd / 2 * h * d; if (jd % 2 == 1){ if ((i1 + j1) % 2 == 0) white += h * d; } h = r.x2 - i2 * d; h = max(h, 0ll); white += jd / 2 * h * d; if (jd % 2 == 1){ if ((i2 + j1) % 2 == 0) white += h * d; } ll w = (j1 - 1) * d - r.y1 + 1; w = max(w, 0ll); white += id / 2 * w * d; if (id % 2 == 1){ if ((i1 + j1) % 2 == 0) white += w * d; } w = r.y2 - j2 * d; w = max(w, 0ll); white += id / 2 * w * d; if (id % 2 == 1){ if ((i1 + j2) % 2 == 0) white += w * d; } h = (i1 - 1) * d - r.x1 + 1, w = (j1 - 1) * d - r.y1 + 1; h = max(h, 0ll); w = max(w, 0ll); if ((i1 + j1) % 2 == 1) white += w * h; w = r.y2 - j2 * d; w = max(w, 0ll); if ((i1 + j2) % 2 == 1) white += w * h; h = r.x2 - i2 * d; h = max(h, 0ll); if ((i2 + j2) % 2 == 1) white += w * h; h = r.x2 - i2 * d, w = (j1 - 1) * d - r.y1 + 1; h = max(h, 0ll); w = max(w, 0ll); if ((i2 + j1) % 2 == 1) white += w * h; ll black = (r.x2 - r.x1 + 1) * (r.y2 - r.y1 + 1) - white; cost += white; cost -= black; debug(white, black); } ans = min(ans, cost); debug(d, cost); } for (ll d : divisors){ /// (1, 1) = white ll cost = (n / d) * (n / d) / 2 * d * d; for (auto r : rectangles){ ll i1 = (r.x1 + d - 2) / d + 1; ll j1 = (r.y1 + d - 2) / d + 1; ll i2 = r.x2 / d; ll j2 = r.y2 / d; ll id = i2 - i1 + 1, jd = j2 - j1 + 1; debug(i1, j1, i2, j2, id, jd); if (id < 0 || jd < 0){ ll S = (r.x2 - r.x1 + 1) * (r.y2 - r.y1 + 1); if ((i1 + j1) % 2 == 0) cost += S; else cost -= S; continue; } ll white = 0; white += (id * jd / 2) * d * d; if ((id * jd) % 2 == 1){ if ((i1 + j1) % 2 == 0) white += d * d; } ll h = (i1 - 1) * d - r.x1 + 1; h = max(h, 0ll); white += jd / 2 * h * d; if (jd % 2 == 1){ if ((i1 + j1) % 2 == 1) white += h * d; } h = r.x2 - i2 * d; h = max(h, 0ll); white += jd / 2 * h * d; if (jd % 2 == 1){ if ((i2 + j1) % 2 == 1) white += h * d; } ll w = (j1 - 1) * d - r.y1 + 1; w = max(w, 0ll); white += id / 2 * w * d; if (id % 2 == 1){ if ((i1 + j1) % 2 == 1) white += w * d; } w = r.y2 - j2 * d; w = max(w, 0ll); white += id / 2 * w * d; if (id % 2 == 1){ if ((i1 + j2) % 2 == 1) white += w * d; } h = (i1 - 1) * d - r.x1 + 1, w = (j1 - 1) * d - r.y1 + 1; h = max(h, 0ll); w = max(w, 0ll); if ((i1 + j1) % 2 == 0) white += w * h; w = r.y2 - j2 * d; w = max(w, 0ll); if ((i1 + j2) % 2 == 0) white += w * h; h = r.x2 - i2 * d; h = max(h, 0ll); if ((i2 + j2) % 2 == 0) white += w * h; h = r.x2 - i2 * d, w = (j1 - 1) * d - r.y1 + 1; h = max(h, 0ll); w = max(w, 0ll); if ((i2 + j1) % 2 == 0) white += w * h; ll black = (r.x2 - r.x1 + 1) * (r.y2 - r.y1 + 1) - white; cost += white; cost -= black; debug(white, black); } ans = min(ans, cost); debug(d, cost); } cout << ans; } int main() { startTime = clock(); ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #ifdef dddxxz freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int TC = 1; // cin >> TC; for (int test = 1; test <= TC; test++) { //debug(test); //cout << "Case #" << test << ": "; solve(test); } cerr << endl << "Time: " << int(getCurrentTime() * 1000) << " ms" << endl; return 0; } /* 6 8 1 2 1 2 2 1 2 1 3 3 3 3 3 4 3 4 3 6 3 6 4 3 4 3 4 4 4 4 5 5 5 5 4 1 4 1 4 4 */

컴파일 시 표준 에러 (stderr) 메시지

chessboard.cpp: In function 'void solve(int)':
chessboard.cpp:19:20: warning: statement has no effect [-Wunused-value]
   19 | #define debug(...) 42
      |                    ^~
chessboard.cpp:73:13: note: in expansion of macro 'debug'
   73 |             debug(i1, j1, i2, j2, id, jd);
      |             ^~~~~
chessboard.cpp:19:20: warning: statement has no effect [-Wunused-value]
   19 | #define debug(...) 42
      |                    ^~
chessboard.cpp:138:13: note: in expansion of macro 'debug'
  138 |             debug(white, black);
      |             ^~~~~
chessboard.cpp:19:20: warning: statement has no effect [-Wunused-value]
   19 | #define debug(...) 42
      |                    ^~
chessboard.cpp:142:9: note: in expansion of macro 'debug'
  142 |         debug(d, cost);
      |         ^~~~~
chessboard.cpp:19:20: warning: statement has no effect [-Wunused-value]
   19 | #define debug(...) 42
      |                    ^~
chessboard.cpp:153:13: note: in expansion of macro 'debug'
  153 |             debug(i1, j1, i2, j2, id, jd);
      |             ^~~~~
chessboard.cpp:19:20: warning: statement has no effect [-Wunused-value]
   19 | #define debug(...) 42
      |                    ^~
chessboard.cpp:218:13: note: in expansion of macro 'debug'
  218 |             debug(white, black);
      |             ^~~~~
chessboard.cpp:19:20: warning: statement has no effect [-Wunused-value]
   19 | #define debug(...) 42
      |                    ^~
chessboard.cpp:222:9: note: in expansion of macro 'debug'
  222 |         debug(d, cost);
      |         ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...