답안 #341802

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
341802 2020-12-31T05:00:42 Z Dilshod_Imomov Red-blue table (IZhO19_stones) C++17
27 / 100
35 ms 1644 KB
# include <bits/stdc++.h>
# define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
# define int long long
# define fi first
# define se second
 
using namespace std;
 
const int N = 1e3 + 7;
const int mod = 1e9 + 7;

char a[N][N];

void solve() {
    int n, m, inv = 0;
    cin >> n >> m;
    if ( m > n ) {
        inv = 1;
        swap( n, m );
    }
    int needr = (m + 2) / 2;
    vector < int > cc(m + 7);
    for ( int i = 1; i <= n; i++ ) {
        for ( int j = 1; j <= m; j++ ) {
            if ( j <= needr ) {
                if ( !inv ) {
                    a[i][j] = '+';
                }
                else {
                    a[i][j] = '-';
                }
            }
            else {
                if ( !inv ) {
                    a[i][j] = '-';
                    cc[j]++;
                }
                else {
                    a[i][j] = '+';
                    cc[j]++;
                }
            }
        }
    }
    vector < int > vc(3);
    vc[0] = n / 3 + ((n % 3) >= 1);
    vc[1] = vc[0] + n / 3 + ((n % 3) == 2);
    int ans = n + (m - needr);
    if ( m & 1 && m > 1 ) {
        int cnt = m - needr - 1, ind = 0;
        ans += cnt;
        int i;
        for ( i = 1; i <= n; i++ ) {
            if ( i <= vc[0] ) {
                ind = 0;
            }
            else if ( i <= vc[1] ) {
                ind = 1;
            }
            else {
                break;
            }
            for ( int j = needr; j > 2; j-- ) {
                if ( !inv ) {
                    a[i][j] = '-';
                    a[i][j + ind * cnt] = '+';
                }
                else {
                    a[i][j] = '+';
                    a[i][j + ind * cnt] = '-';
                }
                cc[j]++;
                cc[j + ind * cnt]--;
            }
        }
        // for ( int j = 1; j <= m; j++ ) {
        //     cout << cc[j] << ' ';
        // }
        // cout << '\n';
        int x = n / 2 - vc[0], turn = 3;
        while ( x ) {
            for ( int j = needr; j > 2; j-- ) {
                if ( j == turn ) {
                    if ( !inv ) {
                        a[i][j] = '-';
                        a[i][m] = '+';
                    }
                    else {
                        a[i][j] = '+';
                        a[i][m] = '-';
                    }
                    cc[j]++;
                    cc[m]--;
                    continue;
                }
            }
            x--;
            turn++;
            i++;
            if ( turn > needr ) {
                turn = 3;
            }
        }
        // for ( int j = 1; j <= m; j++ ) {
        //     cout << cc[j] << ' ';
        // }
        // cout << '\n';
        
        x = n / 2 - ((n / 3) + ((n % 3) == 2));
        turn = needr + 1;
        while ( x ) {
            for ( int j = needr; j > 2; j-- ) {
                if ( !inv ) {
                    if ( a[i][j] != '-' ) {
                        cc[j]++;
                    }
                    a[i][j] = '-';
                    if ( j + cnt != turn ) {
                        a[i][j + cnt] = '+';
                        cc[j + cnt]--;
                    }
                    else {
                        if ( a[i][j + cnt] != '-' )
                            cc[j + cnt]++;
                        a[i][j + cnt] = '-';
                        a[i][m] = '+';
                        cc[m]--;
                    }
                }
                else {
                    a[i][j] = '+';
                    if ( j + cnt != turn ) {
                        a[i][j + cnt] = '-';
                        cc[j + cnt]--;
                    }
                    else {
                        a[i][j + cnt] = '+';
                        a[i][m] = '-';
                        cc[m]--;
                        cc[j + cnt]++;
                    }
                }
            }
            x--;
            i++;
            turn++;
            if ( turn == m ) {
                turn = needr + 1;
            }
        }
        // for ( int j = 1; j <= m; j++ ) {
        //     cout << cc[j] << ' ';
        // }
        // cout << '\n';
        int c = 0;
        for ( int j = 1; j <= m; j++ ) {
            if ( !inv ) {
                if ( a[n][j] == '+' ) {
                    c++;
                }
            }
            else {
                if ( a[n][j] == '-' ) {
                    c++;
                }
            }
        }
        if ( c == 2 ) {
            set < pair < int, int > > st;
            for ( int j = 3; j <= m; j++ ) {
                st.insert({ -cc[j], j });
                // cout << j << " " << cc[j] << endl;
                if ( !inv ) {
                    a[i][j] = '-';
                }
                else {
                    a[i][j] = '+';
                }
                cc[j]++;
            }
            x = cnt;
            while ( x ) {
                int j = st.begin()->se;
                st.erase( st.begin() );
                if ( !inv )
                    a[n][j] = '+';
                else {
                    a[n][j] = '-';
                }
                x--;
            }
        }
    }
    cout << ans << '\n';
    if ( !inv ) {
        for ( int i = 1; i <= n; i++ ) {
            for ( int j = 1; j <= m; j++ ) {
                cout << a[i][j];
            }
            cout << '\n';
        }
    }
    else {
        for ( int i = 1; i <= m; i++ ) {
            for ( int j = 1; j <= n; j++ )  {
                cout << a[j][i];
            }
            cout << '\n';
        }
    }
}

int32_t main() {
    speed; 
    int T = 1;
    cin >> T;
    while ( T-- ) {
        solve();
    }   
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Incorrect 2 ms 384 KB in the table A+B is not equal to 8
# 결과 실행 시간 메모리 Grader output
1 Incorrect 35 ms 1516 KB in the table A+B is not equal to 78
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 34 ms 1644 KB Wrong answer in test 24 24: 35 < 44
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Incorrect 2 ms 384 KB in the table A+B is not equal to 8