Submission #488897

# Submission time Handle Problem Language Result Execution time Memory
488897 2021-11-20T18:57:42 Z Mihai7218 Red-blue table (IZhO19_stones) C++14
54 / 100
161 ms 1448 KB
#include <iostream>
using namespace std;
int t, n, m, mop, nop;
int main()
{
    cin >> t;
    for (int tc = 1; tc <= t; tc++)
    {
        cin >> n >> m;
        if (n >= m)
        {
            if (n % 2 == 0 && n>4 && m > 4)
            {
            cout << max(max(n+ (m/2)-1+(m%2), (m+n-4+m%2+n%2)), n+m-3+m%2) << '\n';
            if (n+ (m/2)-1+(m%2) >= (m+n-4+m%2+n%2) && n+ (m/2)-1+(m%2) >= n+m-3+m%2)
            {
                mop = (m/2)-1+(m%2);
                for (int i = 1; i <= n; i++)
                {
                    for (int j = 1; j <= m; j++)
                    {
                        if (mop-j >= 0)
                        {
                            cout << '-';
                        }
                        else cout << '+';
                    }
                    cout << '\n';
                }
            }
            else if (n+m-3+m%2>(m+n-4+m%2+n%2) && n%2 == 0)
            {
                mop = m-3+m%2;
                nop = (m+m%2-4)/2;
                for (int i = 1; i <= n; i++)
                {
                    for (int j = 1; j <= m; j++)
                    {
                        if (mop-j >= 0)
                        {
                            int ck = 0;
                            for (int k = 1; k <= nop; k++)
                            {
                                if (j%mop == (i*nop+k-nop)%mop)
                                    ck = 1;
                            }
                            if (ck == 1)
                                cout << '+';
                            else cout << '-';
                        }
                        else
                            cout << '+';
                    }
                    cout << '\n';
                }
            }
            else
            {
                mop = n-2+n%2;
                nop = m-2+m%2;
                for (int i = 1; i <= n; i++)
                {
                    for (int j = 1; j <= m; j++)
                    {
                        if (mop - i >= 0)
                        {
                            if (i % 2 == 0)
                            {
                                if ((m/2+1) - j >= 0)
                                {
                                    cout << '+';
                                }
                                else cout << '-';
                            }
                            if (i % 2 == 1)
                            {
                                if (j - (m/2+1) + (1-m%2) >= 0)
                                {
                                    cout << '+';
                                }
                                else cout << '-';
                            }
                        }
                            else cout << '-';
                    }
                    cout << '\n';
                }
            }
            }
            else
            {
                cout << max(n+ (m/2)-1+(m%2), (m+n-4+m%2+n%2)) << '\n';
            if (n+ (m/2)-1+(m%2) >= (m+n-4+m%2+n%2))
            {
                mop = (m/2)-1+(m%2);
                for (int i = 1; i <= n; i++)
                {
                    for (int j = 1; j <= m; j++)
                    {
                        if (mop-j >= 0)
                        {
                            cout << '-';
                        }
                        else cout << '+';
                    }
                    cout << '\n';
                }
            }
            else
            {
                mop = n-2+n%2;
                nop = m-2+m%2;
                for (int i = 1; i <= n; i++)
                {
                    for (int j = 1; j <= m; j++)
                    {
                        if (mop - i >= 0)
                        {
                            if (i % 2 == 0)
                            {
                                if ((m/2+1) - j >= 0)
                                {
                                    cout << '+';
                                }
                                else cout << '-';
                            }
                            if (i % 2 == 1)
                            {
                                if (j - (m/2+1) + (1-m%2) >= 0)
                                {
                                    cout << '+';
                                }
                                else cout << '-';
                            }
                        }
                            else cout << '-';
                    }
                    cout << '\n';
                }
            }
            }
        }
        else
        {
            if (m%2 == 0 && n>4&&m>4)
            {
            cout << max(max(m + (n/2)-1+(n%2), (m+n-4+m%2+n%2)), m+n-3+n%2) << '\n';
            if ( m + (n/2)-1+(n%2) >= (m+n-4+m%2+n%2) && m + (n/2)-1+(n%2) >= m+n-3+n%2)
            {
                mop = (n/2)-1+(n%2);
                for (int i = 1; i <= n; i++)
                {
                    for (int j = 1; j <= m; j++)
                    {
                        if (mop-i >= 0)
                        {
                            cout << '+';
                        }
                        else cout << '-';
                    }
                    cout << '\n';
                }
            }
            else if (m+n-3+n%2>(m+n-4+m%2+n%2) && m%2==0)
            {
                mop = n-3+n%2;
                nop = (n+n%2-4)/2;
                for (int i = 1; i <= n; i++)
                {
                    for (int j = 1; j <= m; j++)
                    {
                        if (mop-i >= 0)
                        {
                            int ck = 0;
                            for (int k = 1; k <= nop; k++)
                            {
                                if (j%mop == (i*nop+k-nop)%mop)
                                    ck = 1;
                            }
                            if (ck == 1)
                                cout << '-';
                            else
                                cout << '+';
                        }
                        else
                            cout << '-';
                    }
                    cout << '\n';
                }
            }
            else
            {
                mop = n-2+n%2;
                nop = m-2+m%2;
                for (int i = 1; i <= n; i++)
                {
                    for (int j = 1; j <= m; j++)
                    {
                        if (mop - i >= 0)
                        {
                            if (i % 2 == 0)
                            {
                                if ((m/2+1) - j >= 0)
                                {
                                    cout << '+';
                                }
                                else cout << '-';
                            }
                            if (i % 2 == 1)
                            {
                                if (j - (m/2+1) + (1-m%2) >= 0)
                                {
                                    cout << '+';
                                }
                                else cout << '-';
                            }
                        }
                            else cout << '-';
                    }
                    cout << '\n';
                }
            }
            }
            else
            {
                cout << max(m + (n/2)-1+(n%2), (m+n-4+m%2+n%2)) << '\n';
            if ( m + (n/2)-1+(n%2) >= (m+n-4+m%2+n%2))
            {
                mop = (n/2)-1+(n%2);
                for (int i = 1; i <= n; i++)
                {
                    for (int j = 1; j <= m; j++)
                    {
                        if (mop-i >= 0)
                        {
                            cout << '+';
                        }
                        else cout << '-';
                    }
                    cout << '\n';
                }
            }
            else
            {
                mop = n-2+n%2;
                nop = m-2+m%2;
                for (int i = 1; i <= n; i++)
                {
                    for (int j = 1; j <= m; j++)
                    {
                        if (mop - i >= 0)
                        {
                            if (i % 2 == 0)
                            {
                                if ((m/2+1) - j >= 0)
                                {
                                    cout << '+';
                                }
                                else cout << '-';
                            }
                            if (i % 2 == 1)
                            {
                                if (j - (m/2+1) + (1-m%2) >= 0)
                                {
                                    cout << '+';
                                }
                                else cout << '-';
                            }
                        }
                            else cout << '-';
                    }
                    cout << '\n';
                }
            }
            }
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 3 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 1220 KB Output is correct
2 Correct 25 ms 1092 KB Output is correct
3 Correct 24 ms 1092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 161 ms 1448 KB in the table A+B is not equal to 45
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 3 ms 332 KB Output is correct
5 Correct 30 ms 1220 KB Output is correct
6 Correct 25 ms 1092 KB Output is correct
7 Correct 24 ms 1092 KB Output is correct
8 Incorrect 161 ms 1448 KB in the table A+B is not equal to 45
9 Halted 0 ms 0 KB -