답안 #333617

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
333617 2020-12-07T08:31:11 Z vipghn2003 Red-blue table (IZhO19_stones) C++14
17 / 100
431 ms 3784 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;
char ans1[N][N],ans2[N][N];

void solve()
{
    int n,m;
    cin>>n>>m;
    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++)
    {
        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 cur.insert(mp(x.fi+1,x.se));
        }
    }
    cur.clear();
    int res2=m;
    for(int i=1;i<=n;i++) cur.insert(mp(0,i));
    for(int j=1;j<=m;j++)
    {
        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 cur.insert(mp(x.fi+1,x.se));
        }
    }
    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 main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin>>t;
    while(t--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2284 KB Output is correct
2 Correct 10 ms 2284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 238 ms 2384 KB in the table A+B is not equal to 6
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2284 KB Output is correct
2 Correct 10 ms 2284 KB Output is correct
3 Incorrect 238 ms 2384 KB in the table A+B is not equal to 6
# 결과 실행 시간 메모리 Grader output
1 Incorrect 431 ms 3784 KB in the table A+B is not equal to 116
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 107 ms 1644 KB in the table A+B is not equal to 44
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2284 KB Output is correct
2 Correct 10 ms 2284 KB Output is correct
3 Incorrect 238 ms 2384 KB in the table A+B is not equal to 6