Submission #502781

#TimeUsernameProblemLanguageResultExecution timeMemory
502781armashkaChessboard (IZhO18_chessboard)C++17
100 / 100
365 ms5828 KiB
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define fast ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); #define all(v) v.begin(),v.end() #define pb push_back #define sz size() #define ft first #define sd second using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef unsigned long long ull; const int N = 2e6 + 10; const ll M = 1e8; const ll inf = 1e18; const ll mod = 1e9; const double Pi = acos(-1); ll binpow(ll x, ll ti) { ll res = 1;while (ti){if(ti & 1)res *= x;x *= x;ti >>= 1; x %= mod; res %= mod;} return res;} ll binmul(ll x, ll ti) { ll res = 0;while (ti){if(ti & 1)res += x;x += x;ti >>= 1; x %= mod; res %= mod;} return res;} ll nok(ll a, ll b) { return (a*b)/__gcd(abs(a),abs(b)) * (a*b > 0 ? 1 : -1); } bool odd(ll n) { return (n % 2 == 1); } bool even(ll n) { return (n % 2 == 0); } struct coor { ll x1, y1, x2, y2; } a[N]; ll n, m, dp[N]; const void solve(/*Armashka*/) { cin >> n >> m; for (int i = 1; i <= m; ++ i) cin >> a[i].x1 >> a[i].y1 >> a[i].x2 >> a[i].y2; vector <ll> v; for (int i = 1; i < n; ++ i) { if (n % i == 0) v.pb(i); } for (int i = 0; i < v.sz; ++ i) { dp[i] = n * n - n * n / (v[i] * v[i]) / 2 * (v[i] * v[i]); } for (int i = 1; i <= m; ++ i) { ll x = a[i].x1, x1 = a[i].x2, y = a[i].y1, y1 = a[i].y2; for (int j = 0; j < v.sz; ++ j) { ll cur = v[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 < v.sz; ++ i) { ans = min({ans, dp[i], n * n - dp[i]}); } cout << ans << "\n"; } signed main() { fast; //freopen("rmq.in", "r", stdin); //freopen("rmq.out", "w", stdout); int tt = 1; //cin >> tt; while (tt --) { solve(); } } // Uaqyt, otedi, ketedi, mulde bilinbei ulger // Kunder seni kutpeidi, susyz ospeidi gulder

Compilation message (stderr)

chessboard.cpp:3: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
    3 | #pragma comment(linker, "/stack:200000000")
      | 
chessboard.cpp: In function 'const void solve()':
chessboard.cpp:44:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |  for (int i = 0; i < v.sz; ++ i) {
      |                    ^
chessboard.cpp:49:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |   for (int j = 0; j < v.sz; ++ j) {
      |                     ^
chessboard.cpp:68:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |  for (int i = 0; i < v.sz; ++ i) {
      |                    ^
#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...