답안 #333626

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
333626 2020-12-07T09:09:22 Z vipghn2003 Red-blue table (IZhO19_stones) C++14
38 / 100
194 ms 2156 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 ans[N][N];

void solve()
{
    int f=0;
    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;
        int can=(m-1)/2;
        while(!cur.empty()&&can)
        {
            can--;
            auto x=*cur.rbegin();
            cur.erase(x);
            int col=x.se;
            if(x.fi+1>(n-x.fi-1))
            {
                f++;
            }
            else del.push_back(mp(x.fi+1,x.se));
        }
        for(auto&x:del) cur.insert(x);
    }
    int res=f+n;
    int row_del=0;
    for(int i=1;i<=n;i++)
    {
        int can=m-(m-1)/2;
        vector<pii>del;
        while(!cur.empty()&&can)
        {
            can--;
            auto x=*cur.rbegin();
            cur.erase(x);
            int col=x.se;
            if(x.fi+1>(n-x.fi-1))
            {
                f++;
            }
            else del.push_back(mp(x.fi+1,x.se));
        }
        for(auto&x:del) cur.insert(x);
        if(res<f+n-i)
        {
            res=f+n-i;
            row_del=i;
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++) ans[i][j]='+';
    }
    for(int i=n-row_del+1;i<=n;i++)
    {
        for(int j=1;j<=m;j++) ans[i][j]='-';
    }
    cur.clear();
    for(int j=1;j<=m;j++) if(row_del<n-row_del) cur.insert(mp(row_del,j));
    for(int i=1;i<=n-row_del;i++)
    {
        vector<pii>del;
        int can=(m-1)/2;
        while(!cur.empty()&&can)
        {
            can--;
            auto x=*cur.rbegin();
            cur.erase(x);
            int col=x.se;
            ans[i][col]='-';
            if(x.fi+1>(n-x.fi-1))
            {
                f++;
            }
            else del.push_back(mp(x.fi+1,x.se));
        }
        for(auto&x:del) cur.insert(x);
    }
    cout<<res<<'\n';
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++) cout<<ans[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(ans[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(ans[i][j]=='+') r++;
            else b++;
        }
        ck+=(b>r);
    }
    assert(res==ck);
    if(ck!=res)
    {
        cout<<n<<' '<<m<<endl;
        exit(0);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin>>t;
    /*for(int i=1;i<=50;i++)
        for(int j=1;j<=50;j++)
            n=i,m=j;
            solve();*/
    while(t--)
    {
        cin>>n>>m;
        solve();
    }
}

Compilation message

stones.cpp: In function 'void solve()':
stones.cpp:26:17: warning: unused variable 'col' [-Wunused-variable]
   26 |             int col=x.se;
      |                 ^~~
stones.cpp:46:17: warning: unused variable 'col' [-Wunused-variable]
   46 |             int col=x.se;
      |                 ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 3 ms 364 KB Output is correct
4 Runtime error 1 ms 620 KB Execution killed with signal 6 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Correct 164 ms 1516 KB Output is correct
2 Correct 194 ms 2028 KB Output is correct
3 Correct 179 ms 2156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 166 ms 1516 KB Wrong answer in test 6 6: 8 < 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 3 ms 364 KB Output is correct
4 Runtime error 1 ms 620 KB Execution killed with signal 6 (could be triggered by violating memory limits)