Submission #1154279

#TimeUsernameProblemLanguageResultExecution timeMemory
1154279KluydQChessboard (IZhO18_chessboard)C++20
39 / 100
38 ms328 KiB
#include <bits/stdc++.h> #define respagold ios_base::sync_with_stdio(0), cin.tie(0); #define ll long long #define int2 __int128_t #define FOR( i, x, n, d ) for( int i = x; i <= n; i += d ) #define FORR( i, x, n, d ) for( int i = x; i >= n; i -= d ) #define F first #define S second #define all(x) x.begin(), x.end() #define sz(x) (int)(x.size()) #define pb push_back #define ins insert #define lb lower_bound #define ub upper_bound #define pii pair <int, int> #define mkp make_pair using namespace std; const int N = 3e5 + 123; const int inf = 2e18; const int mod = 1e9 + 7; int a[N], b[N], c[N][2], n, m, q, k, z, w, x, y, ans; mt19937 rng( chrono::steady_clock::now().time_since_epoch().count()); int rand( int l, int r ) { uniform_int_distribution <int> uid( l, r ); return uid( rng ); } vector <int> v; void solve() { cin >> n >> k; FOR( i, 1, sqrt(n), 1 ) { if( n % i == 0 ) { if( i > 1 && i != n / i ) v.pb(n / i); v.pb(i); } } FOR( i, 0, sz(v) - 1, 1 ) { if( n / v[i] % 2 ) { c[i][0] = ( n * n - v[i] * v[i] ) / 2 + v[i] * v[i]; c[i][1] = ( n * n - v[i] * v[i] ) / 2; } else c[i][0] = c[i][1] = n * n / 2; } FOR( pldf, 1, k, 1 ) { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; FOR( i, 0, sz(v) - 1, 1 ) { FOR( x3, x1, x2, 1 ) { FOR( y3, y1, y2, 1 ) { int da = ( (x3 - 1) / v[i] + (y3 - 1) / v[i] ) % 2; if( da ) c[i][1] --, c[i][0] ++; else c[i][0] --, c[i][1] ++; } } } } ans = inf; FOR( i, 0, sz(v) - 1, 1 ) ans = min( ans, min( c[i][0], c[i][1] )); cout << ans; } signed main() { // freopen("connect.in", "r", stdin); // freopen("connect.out", "w", stdout); respagold int test = 1; if( !test ) cin >> test; while( test -- ) { solve(); } } // solved by KluydQ /* 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 */

Compilation message (stderr)

chessboard.cpp:22:17: warning: overflow in conversion from 'double' to 'int' changes value from '2.0e+18' to '2147483647' [-Woverflow]
   22 | const int inf = 2e18;
      |                 ^~~~
#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...