답안 #167225

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
167225 2019-12-06T19:40:31 Z apostoldaniel854 Red-blue table (IZhO19_stones) C++14
100 / 100
83 ms 5240 KB
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define dbg(x) cerr << #x << " " << x << "\n"
typedef long long ll;
const int N = 1000;
int row[1 + N], col[1 + N], grid[1 + N][1 + N];

void upd (int l, int c, int x) {
    grid[l][c] = max (0, x);
    row[l] += x;
    col[c] += x;
}

int main () {
    ios::sync_with_stdio (false);
    cin.tie (0); cout.tie (0);
    int t;
    cin >> t;
    while (t--) {
        int n, m;
        cin >> n >> m;
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= m; j++)
                grid[i][j] = row[i] = col[j] = 0;
        if (n <= m) {
            for (int i = 1; i <= n; i++) {
                vector <pair <int, int>> v;
                for (int j = 1; j <= m; j++) {
                    if (2 * (col[j] + 1) < n)
                        v.pb ({col[j], j});
                }
                if (v.size () <= m / 2)
                    break;
                sort (v.begin (), v.end ());
                for (int j = 0; j <= m / 2; j++)
                    upd (i, v[j].second, 1);
            }
        }
        else {
            for (int i = 1; i <= n; i++)
                for (int j = 1; j <= m; j++)
                    upd (i, j, 1);

            for (int i = 1; i <= m; i++) {
                vector <pair <int, int>> v;
                for (int j = 1; j <= n; j++) {
                    if (2 * (row[j] - 1) > m)
                        v.pb ({row[j], j});
                }
                if (v.size () <= n / 2)
                    break;
                sort (v.begin (), v.end ());
                reverse (v.begin (), v.end ());
                for (int j = 0; j <= n / 2; j++)
                    upd (v[j].second, i, -1);
            }
        }
        int ans = 0;
        for (int i = 1; i <= n; i++)
            if (row[i] * 2 >= m)
                ans++;
        for (int i = 1; i <= m; i++)
            if (col[i] * 2 < n)
                ans++;
        cout << ans << "\n";
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++)
                if (grid[i][j])
                    cout << "+";
                else
                    cout << "-";
            cout << "\n";
        }
    }
    return 0;
}

Compilation message

stones.cpp: In function 'int main()':
stones.cpp:35:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if (v.size () <= m / 2)
                     ~~~~~~~~~~^~~~~~~~
stones.cpp:53:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if (v.size () <= n / 2)
                     ~~~~~~~~~~^~~~~~~~
# 결과 실행 시간 메모리 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 Correct 4 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 1804 KB Output is correct
2 Correct 71 ms 4164 KB Output is correct
3 Correct 83 ms 4984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 1868 KB Output is correct
2 Correct 68 ms 3976 KB Output is correct
3 Correct 58 ms 3448 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 Correct 4 ms 632 KB Output is correct
5 Correct 70 ms 1804 KB Output is correct
6 Correct 71 ms 4164 KB Output is correct
7 Correct 83 ms 4984 KB Output is correct
8 Correct 66 ms 1868 KB Output is correct
9 Correct 68 ms 3976 KB Output is correct
10 Correct 58 ms 3448 KB Output is correct
11 Correct 18 ms 760 KB Output is correct
12 Correct 68 ms 4316 KB Output is correct
13 Correct 69 ms 4924 KB Output is correct
14 Correct 49 ms 3992 KB Output is correct
15 Correct 76 ms 5240 KB Output is correct
16 Correct 58 ms 4216 KB Output is correct
17 Correct 29 ms 3320 KB Output is correct