Submission #1090037

# Submission time Handle Problem Language Result Execution time Memory
1090037 2024-09-17T15:57:02 Z MrPavlito Chessboard (IZhO18_chessboard) C++17
0 / 100
19 ms 3700 KB
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define sc second
#define endl "\n"
#define pii pair<int,int>

using namespace std;

const int MAXN = 1e5+5;
const int mod7 = 1e9+7;
const long long inf = 1e18;

struct kvadrat{int x1,y1,x2,y2;};
int n,k;
vector<kvadrat> niz;
long long rez = inf;

/// gornjelevo
int check1(int x, int y, int d)
{
    int novox = x/d * d;
    int novoy = y/d * d;
    int kvadrat1 = ((y/d) * (x/d)+1)/2 * (d*d);
    int visina = (x - novox);
    int kvadrat2;
    if(((x-1)/d+1) % 2 == 1)kvadrat2 = visina * ((novoy / d+1)/2) * d;
    else kvadrat2 = visina * ((novoy / d)/2) * d;
    int kvadrat3;
    visina = (y - novoy);
    if(((y-1)/d+1) % 2 == 1)kvadrat3 = visina * ((novox / d+1)/2) * d;
    else kvadrat3 = visina * ((novox / d)/2)* d;
    int kvadrat4 = 0;
    if((((x-1)/d+1) % 2) == (((y-1)/d+1) % 2))kvadrat4 = (x-novox)*(y-novoy);
    return kvadrat1+kvadrat2+kvadrat3+ kvadrat4;
}


signed main()
{
    ios_base::sync_with_stdio(false),cin.tie(0), cout.tie(0);
    int tt=1;
    //cin >> tt;
    while(tt--)
    {

        cin >> n >> k;
        niz.resize(k);
        vector<int> svidelioci;
        svidelioci.pb(1);
        for(int i=0; i<k; i++)cin >> niz[i].x1 >> niz[i].y1 >> niz[i].x2 >> niz[i].y2;
        for(int i=2; i<=sqrt(n); i++)
        {
            if(n%i == 0)
            {
                if(n/i == i)svidelioci.pb(i);
                else
                {
                    svidelioci.pb(i);
                    svidelioci.pb(n/i);
                }
            }
        }
        sort(all(svidelioci));

        for(int x: svidelioci)
        {
            int guess = ((n/x) * (n/x) + 1) / 2 * x * x;
            int guess1 = guess;
            for(auto y: niz)
            {
                int rez1 = check1(y.x2, y.y2, x);
                int rez2 = check1(y.x2, y.y1-1, x);
                int rez3 = check1(y.x1-1, y.y2, x);
                int rez4 = check1(y.x1-1, y.y1-1, x);
                int brbelih = rez1 + rez4 - rez2 - rez3;
                int brcrnih = (y.x2 - y.x1 + 1) * (y.y2 - y.y1 + 1) - brbelih;
               guess = guess - brbelih + brcrnih;
               guess1 = guess1 + brbelih - brcrnih;

            }
            rez = min({rez, guess, guess1});

        }
        cout << rez << endl;

    }
}

/*
 6 8
 3 3 3 3
 1 2 1 2
 3 4 3 4
 5 5 5 5
 4 3 4 3
 4 4 4 4
 2 1 2 1
 3 6 3 6
*/

/*
4 1
4 1 4 4
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 3700 KB Output is correct
2 Incorrect 5 ms 1096 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 3700 KB Output is correct
2 Incorrect 5 ms 1096 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -