Submission #169679

# Submission time Handle Problem Language Result Execution time Memory
169679 2019-12-22T07:17:04 Z blast Red-blue table (IZhO19_stones) C++14
100 / 100
224 ms 2436 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> cnt;

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];
        int ans = 0;
        if (n <= m) {
            for (int i = 1; i <= n; i++)
                for (int j = 1; j <= m; j++)
                    a[i][j] = '-';
            ans = m;
            for (int i = 1; i <= n; i++) {
                int res = (m + 2) / 2, mn = INF;
                for (int j = 1; j <= m; j++) {
                    mn = min(mn, cnt[j]);
                }
                int ct = 0;
                for (int j = 1; j <= m; j++) {
                    ct += (cnt[j] + 1 < (n + 1) / 2 ? 1 : 0);
                }
                if (ct < res) break;
                ans++;
                for (int j = 1; j <= m && res; j++) {
                    if (cnt[j] == mn) {
                        a[i][j] = '+';
                        cnt[j]++;
                        res--;
                    }
                }
                for (int j = 1; j <= m && res; j++) {
                    if (a[i][j] != '+') {
                        a[i][j] = '+';
                        cnt[j]++;
                        res--;
                    }
                }
            }
        } else {
            for (int i = 1; i <= n; i++)
                for (int j = 1; j <= m; j++)
                    a[i][j] = '+';
            ans = n;
            for (int j = 1; j <= m; j++) {
                int res = (n + 2) / 2, mn = INF;
                for (int i = 1; i <= n; i++) {
                    mn = min(mn, cnt[i]);
                }
                int ct = 0;
                for (int i = 1; i <= n; i++) {
                    ct += (cnt[i] + 1 < (m + 1) / 2 ? 1 : 0);
                }
                if (ct < res) break;
                ans++;
                for (int i = 1; i <= n && res; i++) {
                    if (cnt[i] == mn) {
                        a[i][j] = '-';
                        cnt[i]++;
                        res--;
                    }
                }
                for (int i = 1; i <= n && res; i++) {
                    if (a[i][j] != '-') {
                        a[i][j] = '-';
                        cnt[i]++;
                        res--;
                    }
                }
            }
        }
        cout << ans << "\n";
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++)
                cout << a[i][j];
            cout << "\n";
        }
        cnt.clear();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory 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 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 1384 KB Output is correct
2 Correct 198 ms 1960 KB Output is correct
3 Correct 189 ms 2040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 1416 KB Output is correct
2 Correct 172 ms 1668 KB Output is correct
3 Correct 157 ms 1528 KB Output is correct
# Verdict Execution time Memory 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 5 ms 376 KB Output is correct
5 Correct 81 ms 1384 KB Output is correct
6 Correct 198 ms 1960 KB Output is correct
7 Correct 189 ms 2040 KB Output is correct
8 Correct 82 ms 1416 KB Output is correct
9 Correct 172 ms 1668 KB Output is correct
10 Correct 157 ms 1528 KB Output is correct
11 Correct 16 ms 640 KB Output is correct
12 Correct 173 ms 1592 KB Output is correct
13 Correct 178 ms 1528 KB Output is correct
14 Correct 130 ms 1316 KB Output is correct
15 Correct 224 ms 2436 KB Output is correct
16 Correct 164 ms 1788 KB Output is correct
17 Correct 73 ms 992 KB Output is correct