Submission #993096

# Submission time Handle Problem Language Result Execution time Memory
993096 2024-06-05T10:09:38 Z n3rm1n Red-blue table (IZhO19_stones) C++17
17 / 100
17 ms 1372 KB
#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
using namespace std;
const int MAXN = 55;
void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
int n, m;
/// 1 - red
/// 0 - blue
int a[MAXN][MAXN];
int maxhappy, res[MAXN][MAXN];
void check()
{
    int happy = 0;
    for (int i = 1; i <= n; ++ i)
    {
        int cnt_red = 0;
        for (int j = 1; j <= m; ++ j)
            cnt_red += a[i][j];
        if(cnt_red > m - cnt_red)
            happy ++;
    }
    for (int j = 1; j <= m; ++ j)
    {
        int cnt_blue = 0;
        for (int i = 1; i <= n; ++ i)
            cnt_blue += 1 - a[i][j];
        if(cnt_blue > n - cnt_blue)
            happy ++;
    }
    if(happy > maxhappy)
    {
        maxhappy = happy;
       /// cout << "opa update" << endl;
        for (int i = 1; i <= n; ++ i)
        {
            for (int j = 1; j <= m; ++ j)
                res[i][j] = a[i][j];
        }
    }
     /*else if(happy == maxhappy)
     {
         cout << endl;
         for (int i = 1; i <= n; ++ i)
         {
             for (int j = 1; j <= m; ++ j)
                 cout << a[i][j];
             cout << endl;
         }
     }*/
}
void gen(int r, int c)
{
    if(c == m+1)
    {
        c = 1;
        r ++;
    }
    if(r == n+1)
    {
        check();
        return;
    }

    a[r][c] = 1;
    gen(r, c+1);
    a[r][c] = 0;
    gen(r, c+1);
}
void solve_test()
{
    cin >> n >> m;
    memset(res, 0, sizeof(res));
    maxhappy = 0;

     //  maxhappy = 0;
     //  gen(1,1);

    if(n <= 5)
    {
        maxhappy = 0;
        for (int i = 1; i <= n; ++ i)
        {
            for (int j = 1; j <= m; ++ j)
                a[i][j] = 0;
        }
        check();
        for (int i = 1; i <= n; ++ i)
        {
           for (int ii = 1; ii <= n; ++ ii)
        {
            for (int jj = 1; jj <= m; ++ jj)
                a[ii][jj] = 0;
        }
            for (int j = 1; j <= m; ++ j)
            {
                for (int ii = 1; ii <= i; ++ ii)
                    a[ii][j] = 1;
                check();
            }
        }
    }
    /*else if(m <= 5)
    {
        maxhappy = 0;
        for (int i = 1; i <= n; ++ i)
        {
            for (int j = 1; j <= m; ++ j)
                a[i][j] = 1;
        }
        check();
        for (int i = 1; i <= n; ++ i)
        {
            for (int ii = 1; ii <= n; ++ ii)
            {
                for (int jj = 1; jj <= m; ++ jj)
                    a[ii][jj] = 1;
            }
            for (int j = 1; j <= m; ++ j)
            {
                for (int ii = 1; ii <= i; ++ ii)
                    a[ii][j] = 0;
                check();
            }
        }
    }*/

    cout << maxhappy << endl;
    for (int i = 1; i <= n; ++ i)
    {
        for (int j = 1; j <= m; ++ j)
        {
            if(res[i][j])cout << '+';
            else cout << '-';
        }
        cout << endl;
    }
}
int main()
{
    speed();
    int t;
    cin >> t;
    while(t --)
    {
        solve_test();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB in the table A+B is not equal to 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 344 KB in the table A+B is not equal to 0
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 1372 KB in the table A+B is not equal to 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 1372 KB in the table A+B is not equal to 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 344 KB in the table A+B is not equal to 0
4 Halted 0 ms 0 KB -