답안 #502778

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
502778 2022-01-06T15:09:18 Z armashka Chessboard (IZhO18_chessboard) C++17
8 / 100
31 ms 5216 KB
#include <bits/stdc++.h>
 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#define fast ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define all(v) v.begin(),v.end()
#define pb push_back
#define sz size()
#define ft first
#define sd second
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef unsigned long long ull;
 
const int N = 2e6 + 10;
const ll M = 1e8;
const ll inf = 1e18;
const ll mod = 1e9;
const double Pi = acos(-1); 
 
ll binpow(ll x, ll ti) { ll res = 1;while (ti){if(ti & 1)res *= x;x *= x;ti >>= 1; x %= mod; res %= mod;} return res;}
ll binmul(ll x, ll ti) { ll res = 0;while (ti){if(ti & 1)res += x;x += x;ti >>= 1; x %= mod; res %= mod;} return res;}
ll nok(ll a, ll b) { return (a*b)/__gcd(abs(a),abs(b)) * (a*b > 0 ? 1 : -1); }
bool odd(ll n) { return (n % 2 == 1); }                                   
bool even(ll n) { return (n % 2 == 0); }            

struct coor {
	ll x1, y1, x2, y2;
} a[N];

ll n, m, cnt[N], dp[N];

const void solve(/*Armashka*/) {
	cin >> n >> m;
	for (int i = 1; i <= m; ++ i) cin >> a[i].x1 >> a[i].y1 >> a[i].x2 >> a[i].y2;
	vector <ll> v;
	v.pb(1);
	for (int i = 2; i * i <= n; ++ i) {
		if (n % i == 0) {
			v.pb(i);
			if (i * i != n) v.pb(i * i);
		}
	}
	sort(all(v));
	for (int i = 0; i < v.sz; ++ i) {
		dp[i] = n * n - n * n / (v[i] * v[i]) / 2 * (v[i] * v[i]);
	}
	for (int i = 1; i <= m; ++ i) {
		ll x = a[i].x1, x1 = a[i].x2, y = a[i].y1, y1 = a[i].y2;
		for (int j = 0; j < v.sz; ++ j) {
			ll cur = v[j];
            ll X = x1 / (cur * 2) * cur;
            X += min(cur, x1 % (cur * 2));
            ll XX = (x - 1) / (cur * 2) * cur;
            XX += min(cur, (x - 1) % (cur * 2));
            X -= XX;
            ll Y = y1 / (cur * 2) * cur;
            Y += min(cur, y1 % (cur * 2));
            ll YY = (y - 1) / (cur * 2) * cur;
            YY += min(cur, (y - 1) % (cur * 2));
            Y -= YY;
            ll X1 = (x1 - x + 1) - X;
            ll Y1 = (y1 - y + 1) - Y;
            dp[j] -= X * Y + X1 * Y1;
            dp[j] += X * Y1 + X1 * Y;	
		}	
	}
	ll ans = inf;
	for (int i = 0; i < v.sz; ++ i) {
		ans = min({ans, dp[i], n * n - dp[i]});
	}
	cout << ans << "\n";
}
            
signed main() {
    fast;
    //freopen("rmq.in", "r", stdin);
    //freopen("rmq.out", "w", stdout);
    int tt = 1;
    //cin >> tt;
    while (tt --) {                                                             
        solve();
    }
}
// Uaqyt, otedi, ketedi, mulde bilinbei ulger
// Kunder seni kutpeidi, susyz ospeidi gulder

Compilation message

chessboard.cpp:3: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
    3 | #pragma comment(linker, "/stack:200000000")
      | 
chessboard.cpp: In function 'const void solve()':
chessboard.cpp:49:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |  for (int i = 0; i < v.sz; ++ i) {
      |                    ^
chessboard.cpp:54:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |   for (int j = 0; j < v.sz; ++ j) {
      |                     ^
chessboard.cpp:73:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |  for (int i = 0; i < v.sz; ++ i) {
      |                    ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 324 KB Output is correct
2 Incorrect 0 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 3700 KB Output is correct
2 Correct 6 ms 948 KB Output is correct
3 Correct 14 ms 2020 KB Output is correct
4 Correct 14 ms 2172 KB Output is correct
5 Correct 18 ms 3252 KB Output is correct
6 Correct 12 ms 2140 KB Output is correct
7 Correct 3 ms 712 KB Output is correct
8 Correct 11 ms 2116 KB Output is correct
9 Correct 31 ms 5216 KB Output is correct
10 Correct 17 ms 2984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 3700 KB Output is correct
2 Correct 6 ms 948 KB Output is correct
3 Correct 14 ms 2020 KB Output is correct
4 Correct 14 ms 2172 KB Output is correct
5 Correct 18 ms 3252 KB Output is correct
6 Correct 12 ms 2140 KB Output is correct
7 Correct 3 ms 712 KB Output is correct
8 Correct 11 ms 2116 KB Output is correct
9 Correct 31 ms 5216 KB Output is correct
10 Correct 17 ms 2984 KB Output is correct
11 Incorrect 0 ms 332 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 324 KB Output is correct
2 Incorrect 0 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -