Submission #54096

# Submission time Handle Problem Language Result Execution time Memory
54096 2018-07-02T10:20:35 Z egorlifar Chessboard (IZhO18_chessboard) C++17
39 / 100
132 ms 2224 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 {
        exit(1);
        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;
        }
        exit(1);
        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:134:13: warning: unused variable 'ly' [-Wunused-variable]
         int ly = y1[i] / x;
             ^~
chessboard.cpp:135:13: warning: unused variable 'ry' [-Wunused-variable]
         int ry = y2[i] / x;
             ^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 452 KB Output is correct
3 Correct 2 ms 476 KB Output is correct
4 Correct 2 ms 540 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 2 ms 540 KB Output is correct
7 Correct 2 ms 668 KB Output is correct
8 Correct 2 ms 788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 1504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1504 KB Output is correct
2 Correct 2 ms 1504 KB Output is correct
3 Correct 2 ms 1504 KB Output is correct
4 Correct 3 ms 1504 KB Output is correct
5 Correct 2 ms 1504 KB Output is correct
6 Correct 2 ms 1504 KB Output is correct
7 Correct 2 ms 1504 KB Output is correct
8 Correct 2 ms 1504 KB Output is correct
9 Correct 2 ms 1504 KB Output is correct
10 Correct 2 ms 1504 KB Output is correct
11 Correct 2 ms 1504 KB Output is correct
12 Correct 2 ms 1504 KB Output is correct
13 Correct 2 ms 1504 KB Output is correct
14 Correct 2 ms 1504 KB Output is correct
15 Correct 2 ms 1504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1504 KB Output is correct
2 Correct 2 ms 1504 KB Output is correct
3 Correct 2 ms 1504 KB Output is correct
4 Correct 3 ms 1504 KB Output is correct
5 Correct 2 ms 1504 KB Output is correct
6 Correct 2 ms 1504 KB Output is correct
7 Correct 2 ms 1504 KB Output is correct
8 Correct 2 ms 1504 KB Output is correct
9 Correct 2 ms 1504 KB Output is correct
10 Correct 2 ms 1504 KB Output is correct
11 Correct 2 ms 1504 KB Output is correct
12 Correct 2 ms 1504 KB Output is correct
13 Correct 2 ms 1504 KB Output is correct
14 Correct 2 ms 1504 KB Output is correct
15 Correct 2 ms 1504 KB Output is correct
16 Correct 13 ms 1504 KB Output is correct
17 Correct 31 ms 1900 KB Output is correct
18 Correct 45 ms 2224 KB Output is correct
19 Correct 110 ms 2224 KB Output is correct
20 Correct 132 ms 2224 KB Output is correct
21 Correct 32 ms 2224 KB Output is correct
22 Correct 2 ms 2224 KB Output is correct
23 Correct 25 ms 2224 KB Output is correct
24 Correct 40 ms 2224 KB Output is correct
25 Correct 7 ms 2224 KB Output is correct
26 Correct 26 ms 2224 KB Output is correct
27 Correct 35 ms 2224 KB Output is correct
28 Correct 43 ms 2224 KB Output is correct
29 Correct 14 ms 2224 KB Output is correct
30 Correct 3 ms 2224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 1504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 452 KB Output is correct
3 Correct 2 ms 476 KB Output is correct
4 Correct 2 ms 540 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 2 ms 540 KB Output is correct
7 Correct 2 ms 668 KB Output is correct
8 Correct 2 ms 788 KB Output is correct
9 Incorrect 30 ms 1504 KB Output isn't correct
10 Halted 0 ms 0 KB -