QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#412846#6743. water235Guren_WA 0ms3680kbC++2010.4kb2024-05-16 20:18:462024-05-16 20:18:48

Judging History

你现在查看的是最新测评结果

  • [2024-05-16 20:18:48]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3680kb
  • [2024-05-16 20:18:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin >> n >> m;
    if(m==1)
    {
        cout << n / 2 + 1 << endl;
        for (int i = 1; i <= n-1;i++)
        {
            if(i%2==1)
            cout << "1" << endl;
        
        else 
        {
            cout << "0" << endl;
        }
        }
        cout << 1 << endl;
    }
    else 
{
    if(n%2==1)
    {
        if(m==2)
        {
            cout << m + (n - 1) / 2 << endl;
            cout<<1<<" "<<1<<endl;
            int flag = 1;
            for (int i = 2; i <= n; i++)
            {

                if (i % 2 == 1)
                {
                    if (flag == 1)
                    {
                        for (int j = 1; j <= m; j++)
                        {
                            if (j % 2 == 1)
                            {
                                cout << "1 ";
                            }
                            else
                            {
                                cout << "0 ";
                            }
                        }
                        cout << endl;
                    }
                    if (flag == 0)
                    {
                        for (int j = 1; j <= m; j++)
                        {
                            if (j % 2 == 0)
                            {
                                cout << "1 ";
                            }
                            else
                            {
                                cout << "0 ";
                            }
                        }
                        cout << endl;
                    }
                    if (flag == 1)
                        flag = 0;
                    else
                        flag = 1;
                }

                else
                {
                    for (int j = 1; j <= m; j++)
                    {
                        cout << "0 ";
                    }
                    cout << endl;
                }
            }
            
        }
        else if(n==1)
        {
            cout << m / 2 + 1 << endl;
                for (int i = 1; i <= m - 1; i++)
                {
                    if (i % 2 == 1)
                    {
                        cout << "1 ";
                    }
                    else
                    {
                        cout << "0 ";
                    }
                }
                cout << "1" << endl;
            
        }
        else 
        {
       // cout<<n/3
       long long ans = 0;
       int flag1 = 0;
       for (int i = 1; i <= n; i += 2)
       {
           if (m % 2 == 1)
           {
               if (i % 2 == 1 && flag1 == 0)
               {
                   ans += m / 2 + 1;
               }
               else if (i % 2 == 1 && flag1 == 1)
               {
                   ans += m / 2;
               }
               if (flag1 == 0)
                   flag1 = 1;
               else
                   flag1 = 0;
           }
           else
           {
               if (i % 2 == 1 && flag1 == 0)
               {
                   ans += m / 2;
               }
               else if (i % 2 == 1 && flag1 == 1)
               {
                   ans += m / 2;
               }
               if (flag1 == 0)
                   flag1 = 1;
               else
                   flag1 = 0;
           }
       }
       cout << ans << endl;
       
    
       int flag = 1;
       for (int i = 1; i <= n; i++)
       {

           if (i % 2 == 1)
           {
               if (flag == 1)
               {
                   for (int j = 1; j <= m; j++)
                   {
                       if (j % 2 == 1)
                       {
                           cout << "1 ";
                       }
                       else
                       {
                           cout << "0 ";
                       }
                   }
                   cout << endl;
               }
               if (flag == 0)
               {
                   for (int j = 1; j <= m; j++)
                   {
                       if (j % 2 == 0)
                       {
                           cout << "1 ";
                       }
                       else
                       {
                           cout << "0 ";
                       }
                   }
                   cout << endl;
               }
               if (flag == 1)
                   flag = 0;
               else
                   flag = 1;
           }

           else
           {
               for (int j = 1; j <= m; j++)
               {
                   cout << "0 ";
               }
               cout << endl;
           }
     
        }
       }
    
    }
    else 
    {
        if(n==2&&m==2)
        {
            cout << 2 << endl;
            cout << "1 0" << endl;
            cout << "0 1" << endl;
        }
        else if(n==2&&m%2==0)
        {
            long long ans = 0;
            int flag1 = 0;
            for (int i = 1; i <= n; i += 2)
            {
                if (m % 2 == 1)
                {
                    if (i % 2 == 1 && flag1 == 0)
                    {
                        ans += m / 2 + 1;
                    }
                    else if (i % 2 == 1 && flag1 == 1)
                    {
                        ans += m / 2;
                    }
                    if (flag1 == 0)
                        flag1 = 1;
                    else
                        flag1 = 0;
                }
                else
                {
                    if (i % 2 == 1 && flag1 == 0)
                    {
                        ans += m / 2;
                    }
                    else if (i % 2 == 1 && flag1 == 1)
                    {
                        ans += m / 2;
                    }
                    if (flag1 == 0)
                        flag1 = 1;
                    else
                        flag1 = 0;
                }
            }
            cout << ans + 1 << endl;
            int flag = 1;
            for (int i = 1; i <= n - 1; i++)
            {
                if (i % 2 == 1)
                {
                    if (flag == 1)
                    {
                        for (int j = 1; j <= m; j++)
                        {
                            if (j % 2 == 1)
                            {
                                cout << "1 ";
                            }
                            else
                            {
                                cout << "0 ";
                            }
                        }
                        cout << endl;
                    }
                    if (flag == 0)
                    {
                        for (int j = 1; j <= m; j++)
                        {
                            if (j % 2 == 0)
                            {
                                cout << "1 ";
                            }
                            else
                            {
                                cout << "0 ";
                            }
                        }
                        cout << endl;
                    }
                    if (flag == 1)
                        flag = 0;
                    else
                        flag = 1;
                }

                else
                {
                    for (int j = 1; j <= m; j++)
                    {
                        cout << "0 ";
                    }
                    cout << endl;
                }
            }
            for (int i = 1; i <= m - 1; i++)
            {
                cout << "0 ";
            }
            cout << 1;
            cout << endl;
        }
        else
        {
        long long ans = 0;
        int flag1 = 0;
        for (int i = 1; i <= n; i+=2)
        {
            if(m%2==1)
            {
            if (i % 2 == 1 && flag1 == 0)
            {
                ans += m / 2 + 1;
               
            }
            else if (i % 2 == 1 && flag1 == 1)
            {
                ans += m / 2;
                
            }
            if (flag1 == 0)
                flag1 = 1;
            else
                flag1 = 0;
            }
            else 
            {
            if (i % 2 == 1 && flag1 == 0)
            {
                ans += m / 2;
                
            }
            else if (i % 2 == 1 && flag1 == 1)
            {
                ans += m / 2;
               
            }
            if (flag1 == 0)
                flag1 = 1;
            else
                flag1 = 0;
            }
        }
        cout << ans+1 << endl;
        int flag = 1;
        for (int i = 1; i <= n-1; i++)
        {
            if (i % 2 == 1)
            {
                if (flag == 1)
                {
                    for (int j = 1; j <= m; j++)
                    {
                        if (j % 2 == 1)
                        {
                            cout << "1 ";
                        }
                        else
                        {
                            cout << "0 ";
                        }
                    }
                    cout << endl;
                }
                if (flag == 0)
                {
                    for (int j = 1; j <= m; j++)
                    {
                        if (j % 2 == 0)
                        {
                            cout << "1 ";
                        }
                        else
                        {
                            cout << "0 ";
                        }
                    }
                    cout << endl;
                }
                if (flag == 1)
                    flag = 0;
                else
                    flag = 1;
            }

            else
            {
                for (int j = 1; j <= m; j++)
                {
                    cout << "0 ";
                }
                cout << endl;
            }
        }
        cout << "1 ";
        for (int i = 1; i <= m - 1;i++)
        {
            cout << "0 ";
        }
        cout << endl;
    }
}
}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3624kb

input:

2 1

output:

2
1
1

result:

ok The answer is correct.

Test #2:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

3 3

output:

3
1 0 1 
0 0 0 
0 1 0 

result:

ok The answer is correct.

Test #3:

score: 0
Accepted
time: 0ms
memory: 3632kb

input:

1 4

output:

3
1 0 1 1

result:

ok The answer is correct.

Test #4:

score: 0
Accepted
time: 0ms
memory: 3636kb

input:

2 2

output:

2
1 0
0 1

result:

ok The answer is correct.

Test #5:

score: 0
Accepted
time: 0ms
memory: 3680kb

input:

2 4

output:

3
1 0 1 0 
0 0 0 1

result:

ok The answer is correct.

Test #6:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

4 3

output:

4
1 0 1 
0 0 0 
0 1 0 
1 0 0 

result:

ok The answer is correct.

Test #7:

score: -100
Wrong Answer
time: 0ms
memory: 3604kb

input:

4 4

output:

5
1 0 1 0 
0 0 0 0 
0 1 0 1 
1 0 0 0 

result:

wrong answer The answer is wrong: expected = 4, found = 5