답안 #173257

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
173257 2020-01-03T16:52:32 Z GoldeN Red-blue table (IZhO19_stones) C++17
42 / 100
72 ms 1980 KB
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

#define f first
#define s second
#define pb push_back
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;
typedef vector <ll> vl;
typedef vector <int> vi;
typedef vector <bool> vb;
typedef vector <vector <int> > vvi;
typedef vector <vector <ll> > vvl;
typedef vector <pair<int,int> > vii;
typedef vector <pair<ll,ll> > vll;

string itos(int n) {stringstream ss;ss<<n;string s=ss.str();return s;}

ll ppow(ll x,ll y,ll mod) {
    ll res=1;
    while(y) {
        if(y&1) res=res*x%mod;
        y>>=1;
        x=x*x%mod;
    }
    return res;
}

const int N=1005;

char a[N][N];
int w[N],h[N];

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin >> t;
    while (t--) {
        int n,m;
        cin >> n >> m;
        if (n != m) {
            int mx=max(m/2-1+m%2+n,n/2-1+n%2+m);
            cout << mx << "\n";
            if (mx == m/2-1+m%2+n) {
                for (int i=1;i<=n;++i) {
                    for (int j=1;j<=m;++j) {
                        if (j <= m/2-1+m%2) {
                            cout << '-';
                        }
                        else {
                            cout << '+';
                        }
                    }
                    cout << "\n";
                }
            }
            else {
                for (int i=1;i<=n;++i) {
                    for (int j=1;j<=m;++j) {
                        if (i <= n/2-1+n%2) {
                            cout << '+';
                        }
                        else {
                            cout << '-';
                        }
                    }
                    cout << "\n";
                }
            }
            continue;
        }
        set<int> s;
        for (int i=1;i<=m;++i) {
            s.insert(i);
        }
        for (int i=1;i<=n;++i) {
            for (int j=1;j<=m;++j) {
                a[i][j]='-';
                h[j]=0;
            }
            w[i]=0;
        }
        int d=1;
        for (int i=1;i<=n;++i) {
            int cur=0;
            if (d == (n+1)/2) {
                break;
            }
            int need=(m+1)/2+1-m%2;
            while (s.size() && cur < need) {
                a[i][*s.begin()]='+';
                s.erase(s.begin());
                cur++;
            }
            if (cur < need) {
                d++;
                if (d == (n+1)/2) break;
                for (int j=1;j<=m;++j) {
                    s.insert(j);
                }
            }
            else
                continue;
            for (int j=1;j<=m;++j) {
                if (cur == need) break;
                if (a[i][j] == '-') {
                    a[i][j]='+';
                    s.erase(j);
                    cur++;
                }
            }
        }
        int ans=0;
        for (int i=1;i<=n;++i) {
            for (int j=1;j<=m;++j) {
                if (a[i][j] == '+') {
                    w[i]++;
                }
                else {
                    h[j]++;
                }
            }
        }
        for (int i=1;i<=n;++i) {
            if (w[i] > m/2)
                ans++;
        }
        for (int j=1;j<=m;++j) {
            if (h[j] > n/2) {
                ans++;
            }
        }
        cout << ans << "\n";
        for (int i=1;i<=n;++i) {
            for (int j=1;j<=m;++j) {
                cout << a[i][j];
            }
            cout << "\n";
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Incorrect 3 ms 380 KB Wrong answer in test 5 29: 31 < 32
# 결과 실행 시간 메모리 Grader output
1 Incorrect 36 ms 1404 KB Wrong answer in test 97 21: 107 < 116
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 1528 KB Output is correct
2 Correct 68 ms 1980 KB Output is correct
3 Correct 59 ms 1672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Incorrect 3 ms 380 KB Wrong answer in test 5 29: 31 < 32