제출 #1149890

#제출 시각아이디문제언어결과실행 시간메모리
114989012345678Red-blue table (IZhO19_stones)C++20
100 / 100
744 ms9088 KiB
#include <bits/stdc++.h>

using namespace std;

const int nx=1e3+5;

int n, m, ans[nx][nx], s, cnt[nx], res[nx][nx], cur, thm, thn;

void solve()
{
    cin>>n>>m;
    cur=0;
    thn=(n+2)/2;
    thm=(m+2)/2;
    //cout<<"th "<<thn<<' '<<thm<<'\n';
    for (int t=0; t<=n; t++)
    {
        int cs=t+(m-thm);
        for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) ans[i][j]=0;
        for (int i=1; i<=thm; i++) cnt[i]=n-t;
        for (int i=thm+1; i<=m; i++) cnt[i]=n-thn;
        for (int i=1; i<=t; i++) for (int j=1; j<=thm; j++) ans[i][j]=1;
        int idx=thm+1, lst=1;
        for (int i=1; i<=thm; i++)
        {
            while (cnt[i]<thn&&idx<=m)
            {
                //cout<<"here "<<t<<' '<<i<<' '<<cnt[idx]<<'\n';
                if (cnt[idx]==0) idx++, lst=lst+1;
                else if (lst>t)
                {
                    lst=1;
                }
                else if (ans[lst][idx]) idx++, lst=1;
                else
                {
                    swap(ans[lst][i], ans[lst][idx]);
                    cnt[idx]--;
                    cnt[i]++;
                    lst++;
                }
            }
            if (cnt[i]>=thn) cs++;
        }
        if (t==0) cs=m;
        if (cs>cur)
        {
            cur=cs;
            for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) res[i][j]=ans[i][j];
        }
    }
    cout<<cur<<'\n';
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=m; j++) cout<<(res[i][j]?'+':'-');
        cout<<'\n';
    }
}

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    int _t; cin>>_t;
    while (_t--) solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...