Submission #992982

# Submission time Handle Problem Language Result Execution time Memory
992982 2024-06-05T08:45:31 Z simona1230 Red-blue table (IZhO19_stones) C++17
58 / 100
219 ms 9556 KB
#include <bits/stdc++.h>

using namespace std;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int n,m;
int ans[1024][1024];
int curr[1024][1024];

struct row
{
    int x,l;
    row(){}
    row(int _x,int _l)
    {
        x=_x;
        l=_l;
    }

    bool operator<(const row&r)const
    {
        return r.l<l;
    }
};

void solve()
{
    cin>>n>>m;

    int rn=m/2+1;
    int cn=n/2+1;
    //cout<<rn<<" "<<cn<<endl;
    int ans_=0;
    int l=max(0,n/2-5),r=min(n,n/2+5);
    for(int a=l;a<=r;a++)
    {
        priority_queue<row> q;
        for(int i=1;i<=a;i++)
            if(rn-m!=0)q.push({i,rn-m});
        for(int i=a+1;i<=n;i++)
            q.push({i,-m});

        int b=0;
        for(int j=1;j<=m;j++)
        {
            vector<row> v;
            bool pos=1;
            for(int k=1;k<=cn;k++)
            {
                if(q.size()==0)
                {
                    pos=0;
                    break;
                }
                //cout<<j<<" "<<q.top().x<<endl;
                row t=q.top();
                q.pop();
                t.l++;
                curr[t.x][j]=1;
                if(t.l!=0)v.push_back(t);
            }

            if(pos)b++;
            for(int k=0;k<v.size();k++)
                q.push(v[k]);
        }
        ans_=max(ans_,a+b);
        //cout<<a+b<<" "<<a<<" "<<b<<endl;
        if(ans_==a+b)
        {
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=m;j++)
                {
                    ans[i][j]=curr[i][j];
                }
            }
        }

        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                curr[i][j]=0;
            }
        }
    }

    if(1)
    {
        int a=0;
        priority_queue<row> q;
        for(int i=1;i<=a;i++)
            if(rn-m!=0)q.push({i,rn-m});
        for(int i=a+1;i<=n;i++)
            q.push({i,-m});

        int b=0;
        for(int j=1;j<=m;j++)
        {
            vector<row> v;
            bool pos=1;
            for(int k=1;k<=cn;k++)
            {
                if(q.size()==0)
                {
                    pos=0;
                    break;
                }
                //cout<<j<<" "<<q.top().x<<endl;
                row t=q.top();
                q.pop();
                t.l++;
                curr[t.x][j]=1;
                if(t.l!=0)v.push_back(t);
            }

            if(pos)b++;
            for(int k=0;k<v.size();k++)
                q.push(v[k]);
        }
        ans_=max(ans_,a+b);
        //cout<<a+b<<" "<<a<<" "<<b<<endl;
        if(ans_==a+b)
        {
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=m;j++)
                {
                    ans[i][j]=curr[i][j];
                }
            }
        }

        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                curr[i][j]=0;
            }
        }
    }

    if(1)
    {
        int a=n;
        priority_queue<row> q;
        for(int i=1;i<=a;i++)
            if(rn-m!=0)q.push({i,rn-m});
        for(int i=a+1;i<=n;i++)
            q.push({i,-m});

        int b=0;
        for(int j=1;j<=m;j++)
        {
            vector<row> v;
            bool pos=1;
            for(int k=1;k<=cn;k++)
            {
                if(q.size()==0)
                {
                    pos=0;
                    break;
                }
                //cout<<j<<" "<<q.top().x<<endl;
                row t=q.top();
                q.pop();
                t.l++;
                curr[t.x][j]=1;
                if(t.l!=0)v.push_back(t);
            }

            if(pos)b++;
            for(int k=0;k<v.size();k++)
                q.push(v[k]);
        }
        ans_=max(ans_,a+b);
        //cout<<a+b<<" "<<a<<" "<<b<<endl;
        if(ans_==a+b)
        {
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=m;j++)
                {
                    ans[i][j]=curr[i][j];
                }
            }
        }

        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                curr[i][j]=0;
            }
        }
    }
    cout<<ans_<<endl;

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

    memset(ans,0,sizeof(ans));
}

int main()
{
    speed();
    int t;
    cin>>t;
    while(t--)
        solve();
    return 0;
}

Compilation message

stones.cpp: In function 'void solve()':
stones.cpp:70:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<row, std::allocator<row> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |             for(int k=0;k<v.size();k++)
      |                         ~^~~~~~~~~
stones.cpp:125:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<row, std::allocator<row> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  125 |             for(int k=0;k<v.size();k++)
      |                         ~^~~~~~~~~
stones.cpp:180:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<row, std::allocator<row> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  180 |             for(int k=0;k<v.size();k++)
      |                         ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 3 ms 6236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 8676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 3 ms 6236 KB Output is correct
3 Correct 33 ms 8676 KB Output is correct
4 Correct 55 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 219 ms 9548 KB Wrong answer in test 23 57: 76 < 78
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 178 ms 9556 KB Output is correct
2 Correct 128 ms 9276 KB Output is correct
3 Correct 120 ms 9300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 3 ms 6236 KB Output is correct
3 Correct 33 ms 8676 KB Output is correct
4 Correct 55 ms 8540 KB Output is correct
5 Incorrect 219 ms 9548 KB Wrong answer in test 23 57: 76 < 78
6 Halted 0 ms 0 KB -