Submission #488063

# Submission time Handle Problem Language Result Execution time Memory
488063 2021-11-17T15:01:31 Z nickmet2004 Chessboard (IZhO18_chessboard) C++11
8 / 100
19 ms 3180 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N= 1e5 + 5;
int n , k;
int A[N] , B[N] , C[N] , D[N];
int G[N][2];
int ans = 1e18;
void q(int x){
    int sz = n / x;
    for(int i = 0; i < k; ++i){
        G[B[i] / x][(A[i] / x) % 2]++;
    }
    //for(int i = 0;i < sz; ++i)cout << G[i][0] << " " <<G[i][1]<<endl;
    int Y = 0 , L = sz / 2 , ok = 0;
    if(sz % 2 == 1)ok = 1;
    L += ok;
    for(int i= 0;i < sz; ++i){
        Y += L * x * x - G[i][0] + G[i][1];
        if(i & 1^1) L -= ok;
        else L += ok;
    }
    //cout << ok << "ok" << endl;
    //cout << Y << "Y " << endl;
    ans = min(Y , ans);
    L = sz/2;
    Y = 0;
    for(int i = 0; i < sz; ++i){
        Y += G[i][0] + L * x * x - G[i][1];
        if(i & 1^1) L += ok;
        else L -= ok;
        G[i][0] = G[i][1] = 0;
    }
    //cout << Y << " Y " << endl;
    ans = min(Y , ans);
    //cout << endl;
}
 main (){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> k;
    for(int i = 0; i < k; ++i){
        cin >> A[i] >> B[i] >> C[i] >> D[i];
        --A[i] , --B[i] , --C[i] , --D[i];
    }//cout << endl;
    for(int i = 1; i * i <= n; ++i){
        if(n % i ==0){
            if(n/ i != n)q(n / i);
            if(n / i != i) q(i);
        }
    }
    cout << ans;
}

Compilation message

chessboard.cpp: In function 'void q(long long int)':
chessboard.cpp:20:14: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   20 |         if(i & 1^1) L -= ok;
      |            ~~^~~
chessboard.cpp:30:14: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   30 |         if(i & 1^1) L += ok;
      |            ~~^~~
chessboard.cpp: At global scope:
chessboard.cpp:38:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   38 |  main (){
      |  ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 3180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 3180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Incorrect 19 ms 3180 KB Output isn't correct
10 Halted 0 ms 0 KB -