Submission #684169

#TimeUsernameProblemLanguageResultExecution timeMemory
684169mychecksedadChessboard (IZhO18_chessboard)C++17
70 / 100
410 ms3564 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define all(x) x.begin() x.end()
#define MOD (1e9+7)
const int N = 1e6;

ll n, k, ans = 1e18;
vector<pair<int, int>> v;
void solve(){
	cin >> n >> k;
	int a = 0;
	for(int i = 0; i < k; ++i){
		int x1, x2, y1, y2; cin >> x1 >> y1 >> x2 >> y2;
		v.pb({x1-1,y1-1});
	}
	for(ll i = 1; i < n; ++i){
		if(n % i == 0){
			for(int rep = 0; rep < 2; ++rep){
				int c = 0;
				for(int j = 0; j < k; ++j){
					bool type = (v[j].first / i + v[j].second / i) % 2;
					if((type ^ rep) == 0) c--;
					else c++;
				}
				ans = min(ans, c + (rep ? (n/i)*(n/i)/2*i*i : ((n/i)*(n/i) + 1)/2*i*i));
			}

		}
	}
	cout << ans;
}

int main(){
	solve();
	return 0;
}

Compilation message (stderr)

chessboard.cpp: In function 'void solve()':
chessboard.cpp:13:6: warning: unused variable 'a' [-Wunused-variable]
   13 |  int a = 0;
      |      ^
#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...