Submission #1269079

#TimeUsernameProblemLanguageResultExecution timeMemory
1269079ThanhsChessboard (IZhO18_chessboard)C++20
39 / 100
69 ms448 KiB
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define name "TENBAI"
#define fi first
#define se second
#define int long long
#define endl '\n'
#define setmin(x, y) x = min((x), (y))
#define setmax(x, y) x = max((x), (y))
#define sqr(x) ((x) * (x))
#define all(x) x.begin(), x.end()

mt19937 hdp(chrono::high_resolution_clock::now().time_since_epoch().count());
int rand(int l, int r){return l + ((hdp() % (r - l + 1)) + r - l + 1) % (r - l + 1);}

int get(int n, int x, bool b)
{
    int N = n / x;
    int ans = 0;
    int t = (b ? 1 : -1);
    if (N & 1)
        ans = t * x;
    ans += (N & 1 ^ b ? 1 : -1) * (n % x);
    return ans;
}

int get(int l, int r, int x, bool b)
{
    return get(r, x, b) - get(l - 1, x, b);
}

const int NM = 1e5 + 5;

int ans[NM][2];
vector<int> D;

void solve()
{
    int n, m;
    cin >> n >> m;
    for (int i = 1; i < n; i++)
        if (n % i == 0)
        {
            D.push_back(i);
            int t = (n / i) / 2, T = (n / i + 1) / 2;
            ans[i][0] = (T * T + t * t) * i * i;
            ans[i][1] = n * n - ans[i][0];
        }
    while (m--)
    {
        int l1, r1, l2, r2;
        cin >> l1 >> l2 >> r1 >> r2;
        for (int t : D)
            for (int i = 0; i < 2; i++)
                ans[t][i] += get(l1, r1, t, 1) * get(l2, r2, t, i);
    }
    int res = INT_MAX;
    for (int t : D)
        for (int i = 0; i < 2; i++)
            setmin(res, ans[t][i]);
    cout << res;
}

signed main()
{
    if (fopen("in.txt", "r")) 
    {
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    }
    else if (fopen(name".inp", "r"))
    {
        freopen(name".inp", "r", stdin);
        freopen(name".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int tc = 1; 
    // cin >> tc;
    while (tc--)
        solve();
}

Compilation message (stderr)

chessboard.cpp: In function 'int main()':
chessboard.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         freopen("in.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
chessboard.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         freopen("out.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
chessboard.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |         freopen(name".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
chessboard.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         freopen(name".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...