Submission #330714

# Submission time Handle Problem Language Result Execution time Memory
330714 2020-11-26T10:36:41 Z vitkishloh228 Red-blue table (IZhO19_stones) C++14
27 / 100
2000 ms 784 KB
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define endl "\n"
int n, m;
int calc(vector<vector<int>>& a) {
    int cur = 0;
    for (int i = 0; i < n; ++i) {
        int x = 0;
        for (int j = 0; j < m; ++j) {
            if (a[i][j]) x++;
            else x--;
        }
        if (x > 0) cur++;
    }
    for (int j = 0; j < m; ++j) {
        int x = 0;
        for (int i = 0; i < n; ++i) {
            if (a[i][j]) x++;
            else x--;
        }
        if (x < 0) cur++;
    }
    return cur;
}
int main() {
    int tt;
    cin >> tt;
    while (tt--) {
        cin >> n >> m;
        vector<vector<int>> a(n, vector<int>(m));
        int max1 = 0;
        for (int i = -1; i < n; ++i) {
            for (int j = -1; j < m; ++j) {
                a = vector<vector<int>>(n, vector<int>(m));
                for (int k = 0; k <= i; ++k) {
                    for (int z = 0; z <= j; ++z) {
                        a[k][z] = 1;
                    }
                }
                int cur = calc(a);
                if (cur > max1) {
                    max1 = cur;
                }
            }
        }
        cout << max1 << endl;
        bool ok = false;
        for (int i = -1; i < n; ++i) {
            if (ok) continue;
            for (int j = -1; j < m; ++j) {
                a = vector<vector<int>>(n, vector<int>(m));
                for (int k = 0; k <= i; ++k) {
                    for (int z = 0; z <= j; ++z) {
                        a[k][z] = 1;
                    }
                }
                int cur = calc(a);
                if (cur == max1 && !ok) {
                    //max1 = cur;
                    for (auto elem : a) {
                        for (auto u : elem) {
                            if (u) cout << "+";
                            else cout << "-";
                        }
                        cout << endl;
                    }
                    cout << endl;
                    ok = true;
                }
            }
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 48 ms 364 KB Output is correct
4 Incorrect 117 ms 364 KB Wrong answer in test 5 29: 31 < 32
# Verdict Execution time Memory Grader output
1 Execution timed out 2074 ms 784 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2074 ms 748 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 48 ms 364 KB Output is correct
4 Incorrect 117 ms 364 KB Wrong answer in test 5 29: 31 < 32