답안 #1010654

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1010654 2024-06-29T09:10:45 Z LucaIlie Red-blue table (IZhO19_stones) C++17
38 / 100
35 ms 2016 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1000;
char mat[MAX_N][MAX_N];
int sumL[MAX_N], sumC[MAX_N];

int eval( int n, int m ) {
    for ( int l = 0; l < n; l++ )
        sumL[l] = 0;
    for ( int c = 0; c < m; c++ )
        sumC[c] = 0;
    for ( int l = 0; l < n; l++ ) {
        for ( int c = 0; c < m; c++ ) {
            sumL[l] += (mat[l][c] == '+' ? 1 : -1);
            sumC[c] += (mat[l][c] == '+' ? -1 : +1);
        }
    }
    int r = 0;
    for ( int l = 0; l < n; l++ )
        r += (sumL[l] > 0);
    for ( int c = 0; c < m; c++ )
        r += (sumC[c] > 0);
    return r;
}

int solve1( int n, int m ) {
    for ( int l = 0; l < n; l++ ) {
        for ( int c = 0; c < m; c++ ) {
            if ( l == n - 1 && m != 1 )
                mat[l][c] = '-';
            else {
                if ( l < n / 2 ) {
                    if ( c <= m / 2 )
                        mat[l][c] = '+';
                    else
                        mat[l][c] = '-';
                } else {
                    if ( c < (m - 1) / 2 )
                        mat[l][c] = '-';
                    else
                        mat[l][c] = '+';
                }
            }
        }
    }
    return eval( n, m );
}

int solve2( int n, int m ) {
    for ( int l = 0; l < n; l++ ) {
        for ( int c = 0; c < m; c++ ) {
            if ( l >= n - 2 && m != 1 )
                mat[l][c] = '-';
            else {
                if ( l < (n - 1) / 2 ) {
                    if ( c <= m / 2 )
                        mat[l][c] = '+';
                    else
                        mat[l][c] = '-';
                } else {
                    if ( c < (m - 1) / 2 )
                        mat[l][c] = '-';
                    else
                        mat[l][c] = '+';
                }
            }
        }
    }
    return eval( n, m );
}

int solve3( int n, int m ) {
    for ( int l = 0; l < n; l++ ) {
        for ( int c = 0; c < m; c++ ) {
            if ( n > m ) {
                if ( c <= m / 2 )
                    mat[l][c] = '+';
                else
                    mat[l][c] = '-';
            } else {
                if ( l <= n / 2 )
                    mat[l][c] = '-';
                else
                    mat[l][c] = '+';
            }
        }
    }
    return eval( n, m );
}

int main() {
    int t;

    cin >> t;
    for ( ; t > 0; t-- ) {
        int n, m;

        cin >> n >> m;

        int best = 1, r = solve1( n, m );
        if ( solve2( n, m ) > r ) {
            best = 2;
            r = solve2( n, m );
        }
        if ( solve3( n, m ) > r ) {
            best = 3;
            r = solve3( n, m );
        }

        if ( best == 1 )
            solve1( n, m );
        if ( best == 2 )
            solve2( n, m );
        if ( best == 3 )
            solve3( n, m );

        cout << r << "\n";
        for ( int l = 0; l < n; l++ ) {
            for ( int c = 0; c < m; c++ )
                cout << mat[l][c];
            cout << "\n";
        }
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 3 ms 344 KB Wrong answer in test 38 5: 40 < 41
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 1528 KB Output is correct
2 Correct 24 ms 1884 KB Output is correct
3 Correct 23 ms 2016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 29 ms 1372 KB Wrong answer in test 6 6: 8 < 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 3 ms 344 KB Wrong answer in test 38 5: 40 < 41
5 Halted 0 ms 0 KB -