Submission #495246

#TimeUsernameProblemLanguageResultExecution timeMemory
495246IerusChessboard (IZhO18_chessboard)C++17
39 / 100
2097 ms5360 KiB
#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
using namespace std;
#pragma GCC optimize ("unroll-loops,Ofast,O3")
#pragma GCC target("avx,avx2,fma")
#define F first
#define S second
#define sz(x) (int)x.size()
#define pb push_back
#define int long long
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define NFS ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
const int E = 1e6+777;
const long long inf = 1e18+777;
const int N = 1e5+777;
const int MOD = 1e9+7;
vector<int> div(int x){
	vector<int> res = {1};
	for(int i = 2; i <= x / 2; ++i){
		if(x % i == 0){
			res.pb(i);
		}
	}
	return res;
}
vector<int> v[N];
struct block{
	int x, y;
	void read(){
		cin >> x >> y;
		cin >> x >> y;
		v[x].pb(y);
//		v.pb({x, y});
	}
}a[N];
//bool cmp(const pair<int,int> &a, const pair<int,int> &b){
//	if(a.F != b.F)
//		return a.F < b.F;
//	return a.S < b.S;
//}
int n, k;
int get(vector<int> &d, int res = LLONG_MAX){
	for(int i = 1; i <= n; ++i) sort(all(v[i]));
//	cerr << "V\n";
//	for(int i = 1; i <= n; ++i) {
//		if(sz(v[i])){
//			for(auto it : v[i])
//				cerr << i << ' ' << it << '\n';
//		}
//	}
//	d = {2};
	for(auto x : d){
		int sum1 = 0, sum2 = 0, cnt1 = 0, cnt2 = 0;
		bool ok = 1;
//		cerr << "X: " << x << '\n';
		for(int i = 1; i <= n; i += x){
			for(int j = 1; j <= n; j += x){
				int x1 = i, y1 = j, x2 = i + x - 1, y2 = j + x - 1;
				int cur = 0;
				for(int w = x1; w <= x2; ++w){
					int L = lower_bound(all(v[w]), y1) - v[w].begin();
					int R = upper_bound(all(v[w]), y2) - v[w].begin();
//					cerr << "w: " << w << " L: " << L << " R: " << R << "\n";
					cur += max(R-L,0LL);
				}
//				cerr << "x1: " << x1 << " y1: " << y1 << " x2: " << x2 << " y2: " << y2 << " cur: " << cur << '\n';
				if(ok & 1){
					sum1 += cur;
					cnt1 += x * x;
				}else{
					sum2 += cur;
					cnt2 += x * x;
				}			
				ok ^= 1;
			}
			if((n / x) % 2 == 0) ok ^= 1;
		}
		res = min({res, cnt1 - sum1 + sum2, cnt2 - sum2 + sum1});
	}
	return res;
}
main(){
	cin >> n >> k;
	for(int i = 1; i <= k; ++i){
		a[i].read();	
	}
	vector<int> d = div(n);
	cout << get(d) << '\n';
};











Compilation message (stderr)

chessboard.cpp:91:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   91 | main(){
      | ^~~~
#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...