답안 #333620

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
333620 2020-12-07T08:44:42 Z vipghn2003 Red-blue table (IZhO19_stones) C++14
27 / 100
539 ms 3436 KB
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
using namespace std;

const int N=1005;
int n,m;
char ans1[N][N],ans2[N][N];

void solve()
{
    int res1=n;
    set<pii>cur;
    for(int j=1;j<=m;j++) cur.insert(mp(0,j));
    for(int i=1;i<=n;i++)
    {
        vector<pii>del;
        for(int j=1;j<=m;j++) ans1[i][j]='+';
        int can=(m-1)/2;
        while(!cur.empty()&&can)
        {
            can--;
            auto x=*cur.rbegin();
            cur.erase(x);
            int col=x.se;
            ans1[i][col]='-';
            if(x.fi+1>(n-x.fi-1))
            {
                res1++;
            }
            else del.push_back(mp(x.fi+1,x.se));
        }
        for(auto&x:del) cur.insert(x);
    }
    cur.clear();
    int res2=m;
    for(int i=1;i<=n;i++) cur.insert(mp(0,i));
    for(int j=1;j<=m;j++)
    {
        vector<pii>del;
        for(int i=1;i<=n;i++) ans2[i][j]='-';
        int can=(n-1)/2;
        while(!cur.empty()&&can)
        {
            can--;
            auto x=*cur.rbegin();
            cur.erase(x);
            int row=x.se;
            ans2[row][j]='+';
            if(x.fi+1>(m-x.fi-1))
            {
                res2++;
            }
            else del.push_back(mp(x.fi+1,x.se));
        }
        for(auto&x:del) cur.insert(x);
    }
    if(res1<res2)
    {
        swap(res1,res2);
        swap(ans1,ans2);
    }
    cout<<res1<<'\n';
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++) cout<<ans1[i][j];
        cout<<'\n';
    }
    int ck=0;
    for(int i=1;i<=n;i++)
    {
        int r=0,b=0;
        for(int j=1;j<=m;j++)
        {
            if(ans1[i][j]=='+') r++;
            else b++;
        }
        ck+=(r>b);
    }
    for(int j=1;j<=m;j++)
    {
        int r=0,b=0;
        for(int i=1;i<=n;i++)
        {
            if(ans1[i][j]=='+') r++;
            else b++;
        }
        ck+=(b>r);
    }
   assert(ck==res1);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin>>t;
    while(t--)
    {
        cin>>n>>m;
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2284 KB Output is correct
2 Correct 11 ms 2284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 244 ms 2284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2284 KB Output is correct
2 Correct 11 ms 2284 KB Output is correct
3 Correct 244 ms 2284 KB Output is correct
4 Incorrect 405 ms 2412 KB Wrong answer in test 5 29: 31 < 32
# 결과 실행 시간 메모리 Grader output
1 Incorrect 539 ms 3436 KB Wrong answer in test 97 21: 107 < 116
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 193 ms 1644 KB Wrong answer in test 24 24: 35 < 44
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2284 KB Output is correct
2 Correct 11 ms 2284 KB Output is correct
3 Correct 244 ms 2284 KB Output is correct
4 Incorrect 405 ms 2412 KB Wrong answer in test 5 29: 31 < 32