Submission #378515

#TimeUsernameProblemLanguageResultExecution timeMemory
378515cheissmartChessboard (IZhO18_chessboard)C++14
70 / 100
486 ms4332 KiB
#include <bits/stdc++.h> #define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0); #define F first #define S second #define V vector #define PB push_back #define MP make_pair #define EB emplace_back #define ALL(v) (v).begin(), (v).end() #define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef V<int> vi; const int INF = 1e9 + 7; const ll oo = 1e18; signed main() { IO_OP; int n, k; cin >> n >> k; V<array<int, 4>> a(k); for(int i = 0; i < k; i++) { for(int j = 0; j < 4; j++) cin >> a[i][j], a[i][j]--; } ll ans = oo; auto go = [&] (int b) { assert(n % b == 0); int m = n / b; ll black = (ll) m * m / 2 * b * b, white = (ll) n * n - black; int black_type = 1; for(int _ = 0; _ < 2; _++) { int in_black = 0, in_white = 0; for(int i = 0; i < k; i++) { int tt = a[i][0] / b + a[i][1] / b; if(tt % 2 == black_type) in_black++; else in_white++; } assert(in_black <= black); assert(in_white <= white); ans = min(ans, in_white + black - in_black); swap(black, white); black_type ^= 1; } }; for(int i = 1; i * i <= n; i++) { if(n % i == 0) { go(i); if(n / i != i && n / i != n) go(n / i); } } cout << ans << '\n'; }
#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...