답안 #169567

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
169567 2019-12-21T06:42:47 Z blast Red-blue table (IZhO19_stones) C++14
0 / 100
82 ms 1508 KB
#include <bits/stdc++.h>

//#define FILENAME ""

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back

#define F first
#define S second

using namespace std;

//#define int long long

const int N = 1e5 + 5;
const int INF = 1e9 + 5;
const double PI = acos(-1);

typedef long long ll;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

const int mod = 1e9 + 7;

int T, n, m;
map<int,int> cnti, cntj;

int main() {
    #ifdef FILENAME
        freopen(FILENAME".in", "r", stdin);
        freopen(FILENAME ".out", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> T;
    while(T--) {
        cin >> n >> m;
        char a[n + 5][m + 5];
        if (n >= m) {
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++)
                    a[i][j] = '+';
                cntj[i] = m;
            }
            int need = (n + 2) / 2, limit = (m + 2) / 2;
            if (need <= limit) {
                for (int j = 1; j <= m; j++) {
                    if (j % 2 == 1) {
                        for (int i = 1; i <= n; i++) {
                            if (cnti[j] == need || cntj[i] == limit) continue;
                            a[i][j] = '-';
                            cnti[j]++;
                            cntj[i]--;
                        }
                    } else {
                        for (int i = n; i >= 1; i--) {
                            if (cnti[j] == need || cntj[i] == limit) continue;
                            a[i][j] = '-';
                            cnti[j]++;
                            cntj[i]--;
                        }
                    }
                }
            }
            int A = 0, B = 0;
            for (int i = 1; i <= n; i++) {
                int ct1 = 0, ct2 = 0;
                for (int j = 1; j <= m; j++) {
                    if (a[i][j] == '+') ct1++;
                    else ct2++;
                }
                A += (ct1 > ct2 ? 1 : 0);
            }
            for (int j = 1; j <= m; j++) {
                int ct1 = 0, ct2 = 0;
                for (int i = 1; i <= n; i++) {
                    if (a[i][j] == '+') ct1++;
                    else ct2++;
                }
                B += (ct1 < ct2 ? 1 : 0);
            }
            cout << A + B << "\n";
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    cout << a[i][j];
                }
                cout << "\n";
            }
        } else {
            for (int j = 1; j <= m; j++) {
                for (int i = 1; i <= n; i++)
                    a[i][j] = '-';
                cnti[j] = m;
            }
            int need = (m + 2) / 2, limit = (n + 2) / 2;
            if (need <= limit) {
                for (int i = 1; i <= n; i++) {
                    if (i % 2 == 1) {
                        for (int j = 1; j <= m; j++) {
                            if (cnti[j] == limit || cntj[i] == need) continue;
                            a[i][j] = '+';
                            cnti[j]--;
                            cntj[i]++;
                        }
                    } else {
                        for (int j = m; j >= 1; j--) {
                            if (cnti[j] == limit || cntj[i] == need) continue;
                            a[i][j] = '+';
                            cnti[j]--;
                            cntj[i]++;
                        }
                    }
                }
            }
            int A = 0, B = 0;
            for (int i = 1; i <= n; i++) {
                int ct1 = 0, ct2 = 0;
                for (int j = 1; j <= m; j++) {
                    if (a[i][j] == '+') ct1++;
                    else ct2++;
                }
                A += (ct1 > ct2 ? 1 : 0);
            }
            for (int j = 1; j <= m; j++) {
                int ct1 = 0, ct2 = 0;
                for (int i = 1; i <= n; i++) {
                    if (a[i][j] == '+') ct1++;
                    else ct2++;
                }
                B += (ct1 < ct2 ? 1 : 0);
            }
            cout << A + B << "\n";
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    cout << a[i][j];
                }
                cout << "\n";
            }
        }
        cnti.clear();
        cntj.clear();
    }
    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Wrong answer in test 4 3: 4 < 5
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 376 KB Wrong answer in test 3 45: 45 < 46
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Wrong answer in test 4 3: 4 < 5
# 결과 실행 시간 메모리 Grader output
1 Incorrect 35 ms 1380 KB Wrong answer in test 97 21: 97 < 116
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 82 ms 1508 KB Wrong answer in test 24 24: 43 < 44
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Wrong answer in test 4 3: 4 < 5