Submission #159878

# Submission time Handle Problem Language Result Execution time Memory
159878 2019-10-25T07:08:39 Z Dima_Borchuk Red-blue table (IZhO19_stones) C++17
32 / 100
112 ms 1656 KB
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int q;
    cin >> q;
    while(q--){
        int n , m , ans , z;
        cin >> n >> m;
        char a[n][m];
        if(n <= m){
            for(int i = 0; i < n; i++){
                for(int j = 0; j < m; j++){
                    a[i][j] = '-';
                }
            }
            ans = m;
            vector<pair<int,int>> v(m);
            for(int i = 0; i < m; i++){
                v[i].second = i;
            }
            int k[m];
            for(int i = 0; i < m + 1; i++){
                k[i] = n;
            }
            for(int line = 0; line < n; line++){
                sort(v.begin(), v.end());
                for(int l = 0; l < m / 2 + 1; l++){
                    if(k[v[l].second] - 1 > n / 2){
                        v[l].first++;
                        k[v[l].second]--;
                        a[line][v[l].second] = '+';
                    }
                }
            }
            for(int i = 0; i < n; i++){
                z = 0;
                for(int j = 0; j < m; j++){
                    if(a[i][j] == '+') z++;
                }
                if(z > m / 2) ans++;
            }

            cout << ans << endl;
            for(int i = 0; i < n; i++){
                for(int j = 0; j < m; j++){
                    cout << a[i][j];
                }
                cout << endl;
            }
        } else {
            for(int i = 0; i < n; i++){
                for(int j = 0; j < m; j++){
                    a[i][j] = '+';
                }
            }
            ans = n;
            vector<pair<int,int>> v(n);
            for(int i = 0; i < n; i++){
                v[i].second = i;
            }
            int k[n];
            for(int i = 0; i < n + 1; i++){
                k[i] = m;
            }
            for(int line = 0; line < m; line++){
                sort(v.begin(), v.end());
                for(int l = 0; l < n / 2 + 1; l++){
                    if(k[v[l].second] - 1 > m / 2){
                        v[l].first++;
                        k[v[l].second]--;
                        a[v[l].second][line] = '-';
                    }
                }
            }
            for(int i = 0; i < n; i++){
                z = 0;
                for(int j = 0; j < m; j++){
                    if(a[j][i] == '-') z++;
                }
                if(z > n / 2) ans++;
            }

            cout << ans << endl;
            for(int i = 0; i < n; i++){
                for(int j = 0; j < m; j++){
                    cout << a[i][j];
                }
                cout << endl;
            }
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 376 KB in the table A+B is not equal to 16
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Incorrect 18 ms 376 KB in the table A+B is not equal to 16
# Verdict Execution time Memory Grader output
1 Incorrect 112 ms 1312 KB in the table A+B is not equal to 97
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 102 ms 1320 KB Output is correct
2 Correct 64 ms 1656 KB Output is correct
3 Correct 49 ms 1400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Incorrect 18 ms 376 KB in the table A+B is not equal to 16