답안 #89272

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
89272 2018-12-11T08:14:37 Z dimash241 Chessboard (IZhO18_chessboard) C++17
0 / 100
97 ms 2416 KB
# include <stdio.h>
# include <bits/stdc++.h>


#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (int i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (int i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
#define x1 dlp
#define y1 kdkdf
// ROAD to...                                                                                                                                                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
#define int long long
int n, k;
int x1[N], y1[N], x2[N], y2[N];

bool calc (ll x, ll y, ll m) {
	x --, y --;
	x /= m, y /= m;
	x %= 2, y %= 2;
	return (x ^ y);
}

ll solve (ll j) {
	ll v = j;
		ll u = n / j;
		
		ll sm1[2], sm2[2];
		sm1[0] = sm2[1] = 0;
		
		sm1[1] = (((u * u) + 1) / 2) * v * v;
		sm2[0] = ((u * u) / 2) * v * v;
																
		for (int i = 1; i <= k; i ++) {
			ll a = min ((j - (x1[i] - 1) % j) % j, x2[i] - x1[i] + 1);
			ll b = x2[i] % j;
			ll c = min ((j - (y1[i] - 1) % j) % j, y2[i] - y1[i] + 1);
			ll d = y2[i] % j;
			
			if (x1[i] + a > x2[i])
				b = 0;
			if (y1[i] + c > y2[i])
				d = 0;	
						
			bool e = calc (x1[i], y1[i], j);
			sm1[e] += a * c, sm2[e] += a * c;
			
			e = calc (x1[i], y1[i] + c, j);
			ll t = (y2[i] - y1[i] - c + 1) / j;
			ll r = (t + 1) / 2 * a * j;
			sm1[e] += r, sm2[e] += r;
			r = t / 2 * a * j;
			sm1[!e] += r, sm2[!e] += r;
			
			e = calc (x1[i], y2[i], j);
			sm1[e] += a * d, sm2[e] += a * d;
						
			ll xx1 = x1[i] + a;
			if (xx1 > x2[i])
				continue;
			
			e = calc (x2[i], y1[i], j);
			sm1[e] += b * c, sm2[e] += b * c;
			
			e = calc (x2[i], y1[i] + c, j);
			r = (t + 1) / 2 * b * j;
			sm1[e] += r, sm2[e] += r;
			r = t / 2 * b * j;
			sm1[!e] += r, sm2[!e] += r;
			
			e = calc (x1[i], y2[i], j);
			sm1[e] += b * d, sm2[e] += b * d;			
			
			ll xx2 = x2[i] - b;
			if (xx1 > xx2)
				continue;
			
			e = calc (xx1, y1[i], j);
			t = (xx2 - xx1 + 1) / j;
			r = (t + 1) / 2 * c * j;
			sm1[e] += r, sm2[e] += r;
			r = t / 2 * c * j;
			sm1[!e] += r, sm2[!e] += r;
			
			ll yy1 = y1[i] + c;
			if (yy1 > y2[i])
				continue;
			
			e = calc (xx1, y2[i], j);
			r = (t + 1) / 2 * d * j;
			sm1[e] += r, sm2[e] += r;
			r = t / 2 * d * j;
			sm1[!e] += r, sm2[!e] += r;
			
			ll yy2 = y2[i] - d;
			if (yy1 > yy2)
				continue;
									
			e = calc (xx1, yy1, j);
			t = (yy2 - yy1 + 1) / j;
			ll t1 = (xx2 - xx1 + 1) / j;
			r = (((t + 1) / 2) * ((t1 + 1) / 2) + (t / 2) * (t1 / 2)) * j * j;
			sm1[e] += r, sm2[e] += r;
			r = ((t / 2) * ((t1 + 1) / 2) + ((t + 1) / 2) * (t1 / 2)) * j * j;
			sm1[!e] += r, sm2[!e] += r;
		}

	return min(sm2[0] - sm2[1], sm1[1] - sm1[0]);
}

 main () {               
    cin >> n >> k;
    For (i, 1, k) {
    	cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
    }

    ll ans = n * (ll)n;
    For (i, 2, n) {
    	if (n % i == 0)
    		ans = min(ans, solve (i));
    }

    cout << ans;
    
    return Accepted;
}

// Coded By OB

Compilation message

chessboard.cpp:144:8: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  main () {               
        ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 97 ms 2416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 2416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 2416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 97 ms 2416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -