Submission #495345

# Submission time Handle Problem Language Result Execution time Memory
495345 2021-12-18T13:46:03 Z xynex Chessboard (IZhO18_chessboard) C++17
100 / 100
325 ms 4368 KB
/*
* Author: xynex
* Created: 18.12.2021 15:50
* Why am I so stupid? :c
* Slishkom slab
*/

#include <bits/stdc++.h>

// #pragma GCC optimize("inline")
// #pragma GCC optimize("-fgcse,-fgcse-lm")
// #pragma GCC optimize("-ftree-pre,-ftree-vrp")
// #pragma GCC optimize("-ffast-math")
// #pragma GCC optimize("-fipa-sra")
// #pragma GCC optimize("-fpeephole2")
// #pragma GCC optimize("-fsched-spec")
// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("unroll-loops")

using namespace std;

#define ll long long
#define dl double long
#define ull unsigned long long
#define pr pair
#define vt vector
#define ff first
#define ss second
#define mp make_pair
#define sz(a) (int)a.size()
#define pb push_back
#define pf push_front
#define popB pop_back
#define popF pop_front
#define bit_count __builtin_popcount
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed << setprecision(x)

template<typename T> T get_rand(T l, T r) {
    random_device rd;
    mt19937 gen(rd());
    return uniform_int_distribution<T>(l, r)(gen);
}

template<typename T> T lcm(T a, T b) { return a * (b / __gcd(a, b)); }

template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(array<A, S>& a);
template<class T> void read(T& x) { cin >> x; }
void read(double& d) { string t; read(t); d = stod(t); }
void read(long double& d) { string t; read(t); d = stold(t); }
template<class H, class... T> void read(H& h, T&... t) { read(h); read(t...); }
template<class A> void read(vt<A>& x) { for (auto& a : x) read(a); }
template<class A, size_t S> void read(array<A, S>& x) { for (auto& a : x) read(a); }

string to_string(char c) { return string(1, c); }
string to_string(bool b) { return b ? "true" : "false"; }
string to_string(const char* s) { return string(s); }
string to_string(string s) { return s; }
string to_string(vt<bool> v) { string res; for (int i = 0; i < sz(v); ++i) res += char('0' + v[i]); return res; }
template<size_t S> string to_string(bitset<S> b) { string res; for (int i = 0; i < S; ++i) res += char('0' + b[i]); return res; }
template<class T> string to_string(T v) { bool f = 1; string res; for (auto x : v) { if (!f) res += ' '; f = 0; res += to_string(x); } return res; }

template<class A> void write(A x) { cout << to_string(x); }
template<class H, class... T> void write(const H& h, const T&... t) { write(h); write(t...); }

void print() { write("\n"); }
template<class H, class... T> void print(const H& h, const T&... t) { write(h); if (sizeof...(t)) write(' '); print(t...); }

void freop(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

const int MOD = 1e9 + 7;
const int N = 3e6 + 5;
const ll INF = 9e18;
const int M = 3e3 + 5;
const dl pi = acos(-1);
const dl eps = 1e-12;
const int sq = 700;

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
/* ll vs int*/

void precalc() {

}

ll cnt[N];
ll dp[N];
int n, m, q;
vt<ll> del;
struct el {
    int x, y, x1, y1;
} a[N];
ll get() {
    for(int i = 1; i <= m; ++i) {
        ll x = a[i].x, y = a[i].y, x1 = a[i].x1, y1 = a[i].y1;
        for(int j = 0; j < q; ++j) {
            ll cur = del[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 < q; ++i) {
        ans = min(ans, min(dp[i], 1ll * n * n - dp[i]));
    }
    return ans;
}
ll get1() {

}
void solve() {
    read(n, m);
    for(int i = 1; i < n; ++i){
        if(n % i) continue;
        del.pb(i);
    }
    q = sz(del);
    for(int i = 0; i < q; ++i) {
        dp[i] = 1ll * n * n - 1ll * n * n / (del[i] * del[i]) / 2 * (del[i] * del[i]);
       // print(dp[i]);
    }
    for(int i = 1; i <= m; ++i) read(a[i].x, a[i].y, a[i].x1, a[i].y1);
    ll ans = get();
  /*  for(int i = 0; i < q; ++i) {
        dp[i] = 1ll * n * n - dp[i];
    }
    ans = min(ans, get1());*/
    print(ans);
}

int main() {
    //freop("");
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    //read(t);
    precalc();
    for (int i = 1; i <= t; ++i) {
        //write("Case #" + to_string(i) + ": ");
        solve();
    }
    return 0;
}

Compilation message

chessboard.cpp: In function 'long long int get1()':
chessboard.cpp:129:1: warning: no return statement in function returning non-void [-Wreturn-type]
  129 | }
      | ^
chessboard.cpp: In function 'void freop(std::string)':
chessboard.cpp:73:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
chessboard.cpp:74:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 2628 KB Output is correct
2 Correct 6 ms 844 KB Output is correct
3 Correct 13 ms 1872 KB Output is correct
4 Correct 14 ms 1872 KB Output is correct
5 Correct 20 ms 2384 KB Output is correct
6 Correct 13 ms 1580 KB Output is correct
7 Correct 4 ms 580 KB Output is correct
8 Correct 12 ms 1592 KB Output is correct
9 Correct 29 ms 3812 KB Output is correct
10 Correct 16 ms 2244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 9 ms 1100 KB Output is correct
17 Correct 23 ms 2968 KB Output is correct
18 Correct 34 ms 3396 KB Output is correct
19 Correct 71 ms 3012 KB Output is correct
20 Correct 82 ms 3376 KB Output is correct
21 Correct 24 ms 2828 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 17 ms 1544 KB Output is correct
24 Correct 28 ms 3072 KB Output is correct
25 Correct 4 ms 588 KB Output is correct
26 Correct 20 ms 2072 KB Output is correct
27 Correct 25 ms 2388 KB Output is correct
28 Correct 31 ms 3300 KB Output is correct
29 Correct 11 ms 1352 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 2628 KB Output is correct
2 Correct 6 ms 844 KB Output is correct
3 Correct 13 ms 1872 KB Output is correct
4 Correct 14 ms 1872 KB Output is correct
5 Correct 20 ms 2384 KB Output is correct
6 Correct 13 ms 1580 KB Output is correct
7 Correct 4 ms 580 KB Output is correct
8 Correct 12 ms 1592 KB Output is correct
9 Correct 29 ms 3812 KB Output is correct
10 Correct 16 ms 2244 KB Output is correct
11 Correct 1 ms 332 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 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 9 ms 1100 KB Output is correct
27 Correct 23 ms 2968 KB Output is correct
28 Correct 34 ms 3396 KB Output is correct
29 Correct 71 ms 3012 KB Output is correct
30 Correct 82 ms 3376 KB Output is correct
31 Correct 24 ms 2828 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 17 ms 1544 KB Output is correct
34 Correct 28 ms 3072 KB Output is correct
35 Correct 4 ms 588 KB Output is correct
36 Correct 20 ms 2072 KB Output is correct
37 Correct 25 ms 2388 KB Output is correct
38 Correct 31 ms 3300 KB Output is correct
39 Correct 11 ms 1352 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 68 ms 3504 KB Output is correct
42 Correct 34 ms 3944 KB Output is correct
43 Correct 50 ms 3596 KB Output is correct
44 Correct 35 ms 3908 KB Output is correct
45 Correct 34 ms 4088 KB Output is correct
46 Correct 79 ms 3968 KB Output is correct
47 Correct 29 ms 3684 KB Output is correct
48 Correct 40 ms 3652 KB Output is correct
49 Correct 37 ms 3512 KB Output is correct
50 Correct 289 ms 3912 KB Output is correct
51 Correct 299 ms 4164 KB Output is correct
52 Correct 291 ms 3880 KB Output is correct
53 Correct 324 ms 4152 KB Output is correct
54 Correct 281 ms 3904 KB Output is correct
55 Correct 320 ms 4284 KB Output is correct
56 Correct 273 ms 3788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 23 ms 2628 KB Output is correct
10 Correct 6 ms 844 KB Output is correct
11 Correct 13 ms 1872 KB Output is correct
12 Correct 14 ms 1872 KB Output is correct
13 Correct 20 ms 2384 KB Output is correct
14 Correct 13 ms 1580 KB Output is correct
15 Correct 4 ms 580 KB Output is correct
16 Correct 12 ms 1592 KB Output is correct
17 Correct 29 ms 3812 KB Output is correct
18 Correct 16 ms 2244 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 9 ms 1100 KB Output is correct
35 Correct 23 ms 2968 KB Output is correct
36 Correct 34 ms 3396 KB Output is correct
37 Correct 71 ms 3012 KB Output is correct
38 Correct 82 ms 3376 KB Output is correct
39 Correct 24 ms 2828 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 17 ms 1544 KB Output is correct
42 Correct 28 ms 3072 KB Output is correct
43 Correct 4 ms 588 KB Output is correct
44 Correct 20 ms 2072 KB Output is correct
45 Correct 25 ms 2388 KB Output is correct
46 Correct 31 ms 3300 KB Output is correct
47 Correct 11 ms 1352 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 68 ms 3504 KB Output is correct
50 Correct 34 ms 3944 KB Output is correct
51 Correct 50 ms 3596 KB Output is correct
52 Correct 35 ms 3908 KB Output is correct
53 Correct 34 ms 4088 KB Output is correct
54 Correct 79 ms 3968 KB Output is correct
55 Correct 29 ms 3684 KB Output is correct
56 Correct 40 ms 3652 KB Output is correct
57 Correct 37 ms 3512 KB Output is correct
58 Correct 289 ms 3912 KB Output is correct
59 Correct 299 ms 4164 KB Output is correct
60 Correct 291 ms 3880 KB Output is correct
61 Correct 324 ms 4152 KB Output is correct
62 Correct 281 ms 3904 KB Output is correct
63 Correct 320 ms 4284 KB Output is correct
64 Correct 273 ms 3788 KB Output is correct
65 Correct 0 ms 204 KB Output is correct
66 Correct 1 ms 332 KB Output is correct
67 Correct 295 ms 3908 KB Output is correct
68 Correct 307 ms 4040 KB Output is correct
69 Correct 257 ms 3532 KB Output is correct
70 Correct 288 ms 3904 KB Output is correct
71 Correct 295 ms 3804 KB Output is correct
72 Correct 284 ms 3868 KB Output is correct
73 Correct 277 ms 3680 KB Output is correct
74 Correct 306 ms 4048 KB Output is correct
75 Correct 284 ms 3924 KB Output is correct
76 Correct 300 ms 4048 KB Output is correct
77 Correct 62 ms 4220 KB Output is correct
78 Correct 34 ms 3788 KB Output is correct
79 Correct 47 ms 3780 KB Output is correct
80 Correct 50 ms 3776 KB Output is correct
81 Correct 46 ms 3536 KB Output is correct
82 Correct 46 ms 4048 KB Output is correct
83 Correct 36 ms 3768 KB Output is correct
84 Correct 186 ms 4144 KB Output is correct
85 Correct 323 ms 4180 KB Output is correct
86 Correct 1 ms 208 KB Output is correct
87 Correct 1 ms 336 KB Output is correct
88 Correct 325 ms 4368 KB Output is correct
89 Correct 62 ms 1068 KB Output is correct
90 Correct 1 ms 336 KB Output is correct