답안 #502781

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
502781 2022-01-06T15:11:04 Z armashka Chessboard (IZhO18_chessboard) C++17
100 / 100
365 ms 5828 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, 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;
	for (int i = 1; i < n; ++ i) {
		if (n % i == 0) v.pb(i); 
	}
	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:44:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |  for (int i = 0; i < v.sz; ++ i) {
      |                    ^
chessboard.cpp:49:21: 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 j = 0; j < v.sz; ++ j) {
      |                     ^
chessboard.cpp:68:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |  for (int i = 0; i < v.sz; ++ i) {
      |                    ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 324 KB Output is correct
8 Correct 0 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 2392 KB Output is correct
2 Correct 6 ms 964 KB Output is correct
3 Correct 16 ms 1844 KB Output is correct
4 Correct 24 ms 1992 KB Output is correct
5 Correct 33 ms 2116 KB Output is correct
6 Correct 13 ms 1496 KB Output is correct
7 Correct 5 ms 668 KB Output is correct
8 Correct 12 ms 1536 KB Output is correct
9 Correct 29 ms 3304 KB Output is correct
10 Correct 18 ms 2012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 13 ms 1612 KB Output is correct
17 Correct 37 ms 4288 KB Output is correct
18 Correct 45 ms 4904 KB Output is correct
19 Correct 87 ms 4416 KB Output is correct
20 Correct 87 ms 5004 KB Output is correct
21 Correct 22 ms 4148 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 25 ms 2276 KB Output is correct
24 Correct 36 ms 4488 KB Output is correct
25 Correct 4 ms 716 KB Output is correct
26 Correct 20 ms 2920 KB Output is correct
27 Correct 25 ms 3428 KB Output is correct
28 Correct 35 ms 4724 KB Output is correct
29 Correct 10 ms 1860 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 2392 KB Output is correct
2 Correct 6 ms 964 KB Output is correct
3 Correct 16 ms 1844 KB Output is correct
4 Correct 24 ms 1992 KB Output is correct
5 Correct 33 ms 2116 KB Output is correct
6 Correct 13 ms 1496 KB Output is correct
7 Correct 5 ms 668 KB Output is correct
8 Correct 12 ms 1536 KB Output is correct
9 Correct 29 ms 3304 KB Output is correct
10 Correct 18 ms 2012 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 324 KB Output is correct
21 Correct 1 ms 324 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 13 ms 1612 KB Output is correct
27 Correct 37 ms 4288 KB Output is correct
28 Correct 45 ms 4904 KB Output is correct
29 Correct 87 ms 4416 KB Output is correct
30 Correct 87 ms 5004 KB Output is correct
31 Correct 22 ms 4148 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 25 ms 2276 KB Output is correct
34 Correct 36 ms 4488 KB Output is correct
35 Correct 4 ms 716 KB Output is correct
36 Correct 20 ms 2920 KB Output is correct
37 Correct 25 ms 3428 KB Output is correct
38 Correct 35 ms 4724 KB Output is correct
39 Correct 10 ms 1860 KB Output is correct
40 Correct 2 ms 332 KB Output is correct
41 Correct 71 ms 4844 KB Output is correct
42 Correct 43 ms 5480 KB Output is correct
43 Correct 49 ms 4912 KB Output is correct
44 Correct 39 ms 5304 KB Output is correct
45 Correct 44 ms 5684 KB Output is correct
46 Correct 79 ms 5356 KB Output is correct
47 Correct 29 ms 5020 KB Output is correct
48 Correct 40 ms 5020 KB Output is correct
49 Correct 37 ms 4916 KB Output is correct
50 Correct 288 ms 5320 KB Output is correct
51 Correct 317 ms 5624 KB Output is correct
52 Correct 307 ms 5288 KB Output is correct
53 Correct 326 ms 5624 KB Output is correct
54 Correct 320 ms 5216 KB Output is correct
55 Correct 365 ms 5828 KB Output is correct
56 Correct 300 ms 4980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 324 KB Output is correct
8 Correct 0 ms 320 KB Output is correct
9 Correct 22 ms 2392 KB Output is correct
10 Correct 6 ms 964 KB Output is correct
11 Correct 16 ms 1844 KB Output is correct
12 Correct 24 ms 1992 KB Output is correct
13 Correct 33 ms 2116 KB Output is correct
14 Correct 13 ms 1496 KB Output is correct
15 Correct 5 ms 668 KB Output is correct
16 Correct 12 ms 1536 KB Output is correct
17 Correct 29 ms 3304 KB Output is correct
18 Correct 18 ms 2012 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 324 KB Output is correct
21 Correct 1 ms 324 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 328 KB Output is correct
28 Correct 1 ms 324 KB Output is correct
29 Correct 1 ms 324 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 13 ms 1612 KB Output is correct
35 Correct 37 ms 4288 KB Output is correct
36 Correct 45 ms 4904 KB Output is correct
37 Correct 87 ms 4416 KB Output is correct
38 Correct 87 ms 5004 KB Output is correct
39 Correct 22 ms 4148 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 25 ms 2276 KB Output is correct
42 Correct 36 ms 4488 KB Output is correct
43 Correct 4 ms 716 KB Output is correct
44 Correct 20 ms 2920 KB Output is correct
45 Correct 25 ms 3428 KB Output is correct
46 Correct 35 ms 4724 KB Output is correct
47 Correct 10 ms 1860 KB Output is correct
48 Correct 2 ms 332 KB Output is correct
49 Correct 71 ms 4844 KB Output is correct
50 Correct 43 ms 5480 KB Output is correct
51 Correct 49 ms 4912 KB Output is correct
52 Correct 39 ms 5304 KB Output is correct
53 Correct 44 ms 5684 KB Output is correct
54 Correct 79 ms 5356 KB Output is correct
55 Correct 29 ms 5020 KB Output is correct
56 Correct 40 ms 5020 KB Output is correct
57 Correct 37 ms 4916 KB Output is correct
58 Correct 288 ms 5320 KB Output is correct
59 Correct 317 ms 5624 KB Output is correct
60 Correct 307 ms 5288 KB Output is correct
61 Correct 326 ms 5624 KB Output is correct
62 Correct 320 ms 5216 KB Output is correct
63 Correct 365 ms 5828 KB Output is correct
64 Correct 300 ms 4980 KB Output is correct
65 Correct 1 ms 332 KB Output is correct
66 Correct 1 ms 320 KB Output is correct
67 Correct 343 ms 5472 KB Output is correct
68 Correct 317 ms 5448 KB Output is correct
69 Correct 291 ms 4812 KB Output is correct
70 Correct 328 ms 5292 KB Output is correct
71 Correct 313 ms 5220 KB Output is correct
72 Correct 312 ms 5128 KB Output is correct
73 Correct 317 ms 5004 KB Output is correct
74 Correct 334 ms 5400 KB Output is correct
75 Correct 319 ms 5180 KB Output is correct
76 Correct 335 ms 5512 KB Output is correct
77 Correct 68 ms 5752 KB Output is correct
78 Correct 34 ms 5180 KB Output is correct
79 Correct 60 ms 4912 KB Output is correct
80 Correct 65 ms 5232 KB Output is correct
81 Correct 52 ms 4844 KB Output is correct
82 Correct 48 ms 5484 KB Output is correct
83 Correct 41 ms 4952 KB Output is correct
84 Correct 207 ms 5644 KB Output is correct
85 Correct 317 ms 5732 KB Output is correct
86 Correct 2 ms 204 KB Output is correct
87 Correct 1 ms 324 KB Output is correct
88 Correct 333 ms 5820 KB Output is correct
89 Correct 63 ms 1344 KB Output is correct
90 Correct 1 ms 324 KB Output is correct