Submission #54094

# Submission time Handle Problem Language Result Execution time Memory
54094 2018-07-02T10:17:57 Z egorlifar Chessboard (IZhO18_chessboard) C++17
39 / 100
138 ms 17564 KB
/*
ЗАПУСКАЕМ 
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░ 
 */
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <deque>
    
     
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; } 
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const pair<T, U> &_p) { _out << _p.first << ' ' << _p.second; return _out; }
template<typename T, typename U> inline istream &operator>> (istream &_in, pair<T, U> &_p) { _in >> _p.first >> _p.second; return _in; }
template<typename T> inline ostream &operator<< (ostream &_out, const vector<T> &_v) { if (_v.empty()) { return _out; } _out << _v.front(); for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline istream &operator>> (istream &_in, vector<T> &_v) { for (auto &_i : _v) { _in >> _i; } return _in; }
template<typename T> inline ostream &operator<< (ostream &_out, const set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const unordered_set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const unordered_multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const unordered_map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; }
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left228
#define right right228
#define next next228
#define rank rank228
#define prev prev228
#define y1 y1228                                                         
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define files(FILENAME) read(FILENAME), write(FILENAME)
#define pb push_back
#define x first
#define y second
const string FILENAME = "input";
const int MAXN = 100228;

//11:50
//16:50
int n, k;
int x1[MAXN], y1[MAXN], x2[MAXN], y2[MAXN];
long long ans = 1e18;


long long get(int t, int posx, int len, int yl, int yr, int x) {
    long long res = 0;
    int ly = yl / x;
    int ry = yr / x;
    if (ly == ry) {
        if ((ly + posx) % 2 == t) {
            res += 1LL * len * (yr - yl + 1);
        } else {
            res -= 1LL * len * (yr - yl + 1);
        }
    } else {
        if (yl % x != 0) {
            if ((posx + ly) % 2 == t) {
                res += 1LL * len * (x - yl % x);
            } else {
                res -= 1LL * len * (x - yl % x);
            }
            ly++;
        }
        if (yr % x != x - 1) {
            if ((posx + ry) % 2 == t) {
                res += 1LL * len * (yr % x + 1);
            } else {
                res -= 1LL * len * (yr % x + 1);
            }
            ry--;
        }
        if (ly <= ry) {
            if ((posx + ly) % 2 == t) {
                if ((ry - ly + 1) % 2) {
                    res += 1LL * len * x;
                }
            } else {
                if ((ry - ly + 1) % 2) {
                    res -= 1LL * len * x;
                }
            }
        }
    }
    return res;
}


long long check(int t, int x) {
    long long res = 0;
    if (t == 1) {
        res += 1LL * ((n / x) * (n / x) + 1) / 2 * x * x;
    } else {
        res += 1LL * ((n / x) * (n / x) ) / 2 * x * x;
    }
   // cout << res << endl;
    for (int i = 0; i < k; i++) {
        int lx = x1[i] / x;
        int rx = x2[i] / x;
        int ly = y1[i] / x;
        int ry = y2[i] / x;
        if (lx == rx) {
            res += get(t, lx, x2[i] - x1[i] + 1, y1[i], y2[i], x);
            continue;
        }
        if (x1[i] % x != 0) {
            res += get(t, lx, x - x1[i] % x, y1[i], y2[i], x);
            lx++;
        }
        if (x2[i] % x != x - 1) {
            res += get(t, rx, x2[i] % x + 1, y1[i], y2[i], x);
            rx--;
        }
        if (lx <= rx) {
            if ((rx - lx + 1) % 2 == 1) {
                res += get(t, lx, x, y1[i], y2[i], x);
            }
        }
    }
    return res;
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//read(FILENAME);
    cin >> n >> k;
    for (int i = 0; i < k; i++) {
        cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
        x1[i]--;
        y1[i]--;
        x2[i]--;
        y2[i]--;
    }
    for (int i = 1; i < n; i++) {
        if (n % i == 0) {
            chkmin(ans, check(0, i));
            chkmin(ans, check(1, i));
        }
    }
    cout << ans << '\n';
}

Compilation message

chessboard.cpp: In function 'long long int check(int, int)':
chessboard.cpp:133:13: warning: unused variable 'ly' [-Wunused-variable]
         int ly = y1[i] / x;
             ^~
chessboard.cpp:134:13: warning: unused variable 'ry' [-Wunused-variable]
         int ry = y2[i] / x;
             ^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 472 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 660 KB Output is correct
6 Correct 3 ms 660 KB Output is correct
7 Correct 2 ms 660 KB Output is correct
8 Correct 2 ms 816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 3168 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3168 KB Output is correct
2 Correct 2 ms 3168 KB Output is correct
3 Correct 3 ms 3168 KB Output is correct
4 Correct 3 ms 3168 KB Output is correct
5 Correct 3 ms 3168 KB Output is correct
6 Correct 2 ms 3168 KB Output is correct
7 Correct 2 ms 3168 KB Output is correct
8 Correct 3 ms 3168 KB Output is correct
9 Correct 2 ms 3168 KB Output is correct
10 Correct 2 ms 3168 KB Output is correct
11 Correct 4 ms 3168 KB Output is correct
12 Correct 3 ms 3168 KB Output is correct
13 Correct 3 ms 3168 KB Output is correct
14 Correct 4 ms 3168 KB Output is correct
15 Correct 3 ms 3168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3168 KB Output is correct
2 Correct 2 ms 3168 KB Output is correct
3 Correct 3 ms 3168 KB Output is correct
4 Correct 3 ms 3168 KB Output is correct
5 Correct 3 ms 3168 KB Output is correct
6 Correct 2 ms 3168 KB Output is correct
7 Correct 2 ms 3168 KB Output is correct
8 Correct 3 ms 3168 KB Output is correct
9 Correct 2 ms 3168 KB Output is correct
10 Correct 2 ms 3168 KB Output is correct
11 Correct 4 ms 3168 KB Output is correct
12 Correct 3 ms 3168 KB Output is correct
13 Correct 3 ms 3168 KB Output is correct
14 Correct 4 ms 3168 KB Output is correct
15 Correct 3 ms 3168 KB Output is correct
16 Correct 15 ms 3348 KB Output is correct
17 Correct 36 ms 5584 KB Output is correct
18 Correct 49 ms 7332 KB Output is correct
19 Correct 136 ms 8688 KB Output is correct
20 Correct 138 ms 10484 KB Output is correct
21 Correct 34 ms 11480 KB Output is correct
22 Correct 2 ms 11480 KB Output is correct
23 Correct 29 ms 11560 KB Output is correct
24 Correct 56 ms 13724 KB Output is correct
25 Correct 10 ms 13724 KB Output is correct
26 Correct 34 ms 14292 KB Output is correct
27 Correct 39 ms 15620 KB Output is correct
28 Correct 74 ms 17564 KB Output is correct
29 Correct 23 ms 17564 KB Output is correct
30 Correct 5 ms 17564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 3168 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 472 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 660 KB Output is correct
6 Correct 3 ms 660 KB Output is correct
7 Correct 2 ms 660 KB Output is correct
8 Correct 2 ms 816 KB Output is correct
9 Incorrect 37 ms 3168 KB Output isn't correct
10 Halted 0 ms 0 KB -