Submission #344250

# Submission time Handle Problem Language Result Execution time Memory
344250 2021-01-05T10:27:39 Z Sprdalo Red-blue table (IZhO19_stones) C++17
100 / 100
70 ms 2560 KB
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
       
        
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; } 
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const pair<T, U> &_p) { _out << _p.first << ' ' << _p.second; return _out; }
template<typename T, typename U> inline istream &operator>> (istream &_in, pair<T, U> &_p) { _in >> _p.first >> _p.second; return _in; }
template<typename T> inline ostream &operator<< (ostream &_out, const vector<T> &_v) { if (_v.empty()) { return _out; } _out << _v.front(); for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline istream &operator>> (istream &_in, vector<T> &_v) { for (auto &_i : _v) { _in >> _i; } return _in; }
template<typename T> inline ostream &operator<< (ostream &_out, const set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const unordered_set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const unordered_multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const unordered_map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; }
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left228
#define right right228
#define rank rank228
#define y1 y1228                                                         
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define files(FILENAME) read(FILENAME), write(FILENAME)
#define pb push_back
const string FILENAME = "input";
const int MAXN = 1005;
 
char c[2] = {'-', '+'};
int n, m;
char ans[MAXN][MAXN];
int cur[MAXN];
 
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //read(FILENAME);
    int t;
    cin >> t;
    for (int it = 0; it < t; it++) {
        cin >> n >> m;
        bool inv = false;
        if (n > m) {
            swap(n, m);
            inv = true;
        }
        for (int i = 0; i < n; i++) {
            cur[i] = 0;
            for (int j = 0; j < m; j++) {
                ans[i][j] = c[0];
            }
        }
        int t = n / 2;
        while (t <= n - t) {
            t++;
        }
        int rem = n - t;
        int need = m / 2;
        while (need <= m - need) {
            need++;
        }
        //cout << need << endl;
        //cout << rem << endl;
        int res = 0;
        for (int cnst = n; cnst >= 0; cnst--) {
            if (cnst * need <= rem * m) {
                res = cnst;
                break;
            }
        }
       // cout << res << endl;
        for (int i = 0; i < m; i++) {
            vector<pair<int, int> > st;
            for (int j = 0; j < res; j++) {
                st.pb({cur[j], j});
            }
            sort(all(st));
            for (int j = 0; j < rem; j++) {
                ans[st[j].second][i] = c[1];
                cur[st[j].second]++;
            }
        }
        cout << m + res << '\n';
        if (inv) {
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    cout << (char)(ans[j][i] ^ c[0] ^ c[1]);
                }
                cout << '\n';
            }
        } else {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    cout << ans[i][j];
                }
                cout << '\n';
            }
        }
    }
    return 0; 
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 4 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 1516 KB Output is correct
2 Correct 68 ms 2028 KB Output is correct
3 Correct 58 ms 2028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 1516 KB Output is correct
2 Correct 58 ms 2028 KB Output is correct
3 Correct 52 ms 1644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 4 ms 364 KB Output is correct
5 Correct 60 ms 1516 KB Output is correct
6 Correct 68 ms 2028 KB Output is correct
7 Correct 58 ms 2028 KB Output is correct
8 Correct 60 ms 1516 KB Output is correct
9 Correct 58 ms 2028 KB Output is correct
10 Correct 52 ms 1644 KB Output is correct
11 Correct 13 ms 640 KB Output is correct
12 Correct 52 ms 1644 KB Output is correct
13 Correct 52 ms 1772 KB Output is correct
14 Correct 39 ms 1388 KB Output is correct
15 Correct 70 ms 2560 KB Output is correct
16 Correct 51 ms 1900 KB Output is correct
17 Correct 22 ms 1132 KB Output is correct