답안 #674962

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
674962 2022-12-26T17:30:36 Z LucaIlie Chessboard (IZhO18_chessboard) C++17
8 / 100
111 ms 7444 KB
#include <bits/stdc++.h>

#define int long long

using namespace std;

const int maxK = 1e5;

struct rectangle {
    int l1, c1, l2, c2;
};

int l;
rectangle black[maxK];

int nxt( int x ) {
    return (x / l + 1) * l;
}

int prv( int x ) {
    return x / l * l - 1;
}

long long wbSq( int lin, int col, bool color ) {
    int x = (lin + 1) / 2, y = col / 2;
    
    if ( lin == 0 || col == 0 )
        return 0;
    return (x * x + y * y - 2 * x * y) * (color == 0 ? 1 : -1);
}

long long getCost( rectangle r ) {
    int l1 = r.l1, c1 = r.c1, l2 = r.l2, c2 = r.c2;
    long long cost = 0;

    if ( l1 / l == l2 / l && c1 / l == c2 / l )
        cost += (l2 - l1 + 1) * (c2 - c1 + 1) * wbSq( 1, 1, (l1 / l + c1 / l) % 2 );
    else if ( l1 / l == l2 / l ) {
        cost += (l2 - l1 + 1) * (nxt( c1 ) - c1) * wbSq( 1, 1, (l1 / l + c1 / l) % 2 );
        cost += (l2 - l1 + 1) * (c2 - prv( c2 )) * wbSq( 1, 1, (l2 / l + c2 / l) % 2 );

        cost += (l2 - l1 + 1) * wbSq( 1, c2 / l - c1 / l - 1, (l1 / l + nxt( c1 ) / l) % 2 );
    } else if ( c1 / l == c2 / l ) {

        cost += (nxt( l1 ) - l1) * (c2 - c1 + 1) * wbSq( 1, 1, (l1 / l + c2 / l) % 2 );
        cost += (l2 - prv( l2 )) * (c2 - c1 + 1) * wbSq( 1, 1, (l2 / l + c2 / l) % 2 );

        cost += (c2 - c1 + 1) * wbSq( l2 / l - l1 / l - 1, 1, (nxt( l1 ) / l + c1 / l) % 2 );
    } else {
        cost += (nxt( l1 ) - l1) * (nxt( c1 ) - c1) * wbSq( 1, 1, (l1 / l + c1 / l) % 2 );
        cost += (nxt( l1 ) - l1) * (c2 - prv( c2 )) * wbSq( 1, 1, (l1 / l + c2 / l) % 2 );
        cost += (l2 - prv( l2 )) * (nxt( c1 ) - c1) * wbSq( 1, 1, (l2 / l + c1 / l) % 2 );
        cost += (l2 - prv( l2 )) * (c2 - prv( c2 )) * wbSq( 1, 1, (l2 / l + c2 / l) % 2 );

        cost += (nxt( l1 ) - l1) * wbSq( 1, c2 / l - c1 / l - 1, (l1 / l + nxt( c1 ) / l) % 2 );
        cost += (nxt( c1 ) - c1) * wbSq( l2 / l - l1 / l - 1, 1, (nxt( l1 ) / l + c1 / l) % 2 );
        cost += (l2 - prv( l2 )) * wbSq( 1, c2 / l - c1 / l - 1, (l2 / l + nxt( c1 ) / l) % 2 );
        cost += (c2 - prv( c2 )) * wbSq( l2 / l - l1 / l - 1, 1, (nxt( l1 ) / l + c2 / l) % 2 );

        cost += l * l * wbSq( l2 / l - l1 / l - 1, c2 / l - c1 / l - 1, (nxt( l1 ) / l + nxt( c1 ) / l) % 2 );
    }

    printf( "%d %d %d %d %d: %d\n", l, l1, c1, l2, c2, cost );
    return cost;
}

signed main() {
    int n, k;
    long long cost, minCost;

    cin >> n >> k;
    for ( int i = 0; i < k; i++ ) {
        cin >> black[i].l1 >> black[i].c1 >> black[i].l2 >> black[i].c2;
        black[i].l1--;
        black[i].c1--;
        black[i].l2--;
        black[i].c2--;
    }

    minCost = n * n;
    for ( l = 1; l < n; l++ ) {
        if ( n % l == 0 ) {
            int x = (n / l + 1) / 2, y = n / l / 2;

            cost = (l * l) * (x * x + y * y);
            for ( int i = 0; i < k; i++ )
                cost += getCost( black[i] );
            minCost = min( minCost, cost );

            cost = 2 * x * y * l * l;
            for ( int i = 0; i < k; i++ )
                cost -= getCost( black[i] );
            minCost = min( minCost, cost );
        }
    }

    cout << minCost;

    return 0;
}

Compilation message

chessboard.cpp: In function 'long long int getCost(rectangle)':
chessboard.cpp:63:15: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
   63 |     printf( "%d %d %d %d %d: %d\n", l, l1, c1, l2, c2, cost );
      |              ~^                     ~
      |               |                     |
      |               int                   long long int
      |              %lld
chessboard.cpp:63:18: warning: format '%d' expects argument of type 'int', but argument 3 has type 'long long int' [-Wformat=]
   63 |     printf( "%d %d %d %d %d: %d\n", l, l1, c1, l2, c2, cost );
      |                 ~^                     ~~
      |                  |                     |
      |                  int                   long long int
      |                 %lld
chessboard.cpp:63:21: warning: format '%d' expects argument of type 'int', but argument 4 has type 'long long int' [-Wformat=]
   63 |     printf( "%d %d %d %d %d: %d\n", l, l1, c1, l2, c2, cost );
      |                    ~^                      ~~
      |                     |                      |
      |                     int                    long long int
      |                    %lld
chessboard.cpp:63:24: warning: format '%d' expects argument of type 'int', but argument 5 has type 'long long int' [-Wformat=]
   63 |     printf( "%d %d %d %d %d: %d\n", l, l1, c1, l2, c2, cost );
      |                       ~^                       ~~
      |                        |                       |
      |                        int                     long long int
      |                       %lld
chessboard.cpp:63:27: warning: format '%d' expects argument of type 'int', but argument 6 has type 'long long int' [-Wformat=]
   63 |     printf( "%d %d %d %d %d: %d\n", l, l1, c1, l2, c2, cost );
      |                          ~^                        ~~
      |                           |                        |
      |                           int                      long long int
      |                          %lld
chessboard.cpp:63:31: warning: format '%d' expects argument of type 'int', but argument 7 has type 'long long int' [-Wformat=]
   63 |     printf( "%d %d %d %d %d: %d\n", l, l1, c1, l2, c2, cost );
      |                              ~^                        ~~~~
      |                               |                        |
      |                               int                      long long int
      |                              %lld
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 111 ms 7444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 111 ms 7444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Incorrect 111 ms 7444 KB Output isn't correct
10 Halted 0 ms 0 KB -