Submission #341314

#TimeUsernameProblemLanguageResultExecution timeMemory
341314Dilshod_ImomovRed-blue table (IZhO19_stones)C++17
0 / 100
213 ms1576 KiB
# 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], cnt[N];

void solve() {
    int n, m;
    cin >> n >> m;
    int ans = m;
    for ( int i = 1; i <= n; i++ ) {
        for ( int j = 1; j <= m; j++ ) {
            a[i][j] = '-';
            cnt[j] = 0;
        }
    }
    int ind = 0;
    for ( int i = 1; i <= n; i++ ) {
        int nd = (m + 1) / 2;
        for ( int j = 1; j <= m; j++ ) {
            if ( ((n - cnt[j]) < (n + 1) / 2) && nd ) {
                nd--;
                cnt[j]++;
                a[i][j] = '+';
            }
        }
        set < pair < int, int > > st;
        for ( int j = 1; j <= m; j++ ) {
            if ( a[i][j] == '-' ) {
                st.insert( { cnt[j], j } );
            }
        }
        while ( nd ) {
            int j = st.begin()->se;
            st.erase( st.begin() );
            a[i][j] = '+';
            nd--;
            cnt[j]++;
        }
        int c = i;
        for ( int j = 1; j <= m; j++ ) {
            if ( (n - cnt[j]) >= (n + 1) / 2 ) {
                c++;
            }
        }
        if ( c > ans ) {
            ind = i;
            ans = c;
        }
    }
    for ( int i = 1; i <= n; i++ ) {
        for ( int j = 1; j <= m; j++ ) {
            a[i][j] = '-';
            cnt[j] = 0;
        }
    }
    for ( int i = 1; i <= ind; i++ ) {
        int nd = (m + 1) / 2;
        for ( int j = 1; j <= m; j++ ) {
            if ( ((n - cnt[j]) < (n + 1) / 2) && nd ) {
                nd--;
                cnt[j]++;
                a[i][j] = '+';
            }
        }
        set < pair < int, int > > st;
        for ( int j = 1; j <= m; j++ ) {
            if ( a[i][j] == '-' ) {
                st.insert( { cnt[j], j } );
            }
        }
        while ( nd ) {
            int j = st.begin()->se;
            st.erase( st.begin() );
            a[i][j] = '+';
            nd--;
            cnt[j]++;
        }
        int c = i;
        for ( int j = 1; j <= m; j++ ) {
            if ( (n - cnt[j]) >= (n + 1) / 2 ) {
                c++;
            }
        }
        if ( c > ans ) {
            ind = i;
            ans = c;
        }
    }
    cout << ans << '\n';
    for ( int i = 1; i <= n; i++ ) {
        for ( int j = 1; j <= m; j++ ) {
            cout << a[i][j];
        }
        cout << '\n';
    }
}

int32_t main() {
    speed; 
    int T = 1;
    cin >> T;
    while ( T-- ) {
        solve();
    }   
}
#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...