Submission #158905

# Submission time Handle Problem Language Result Execution time Memory
158905 2019-10-19T12:10:12 Z elizavetaa Red-blue table (IZhO19_stones) C++14
100 / 100
95 ms 2424 KB
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#include <bits/stdc++.h>

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/detail/standard_policies.hpp>

#define pb push_back
#define F first
#define S second
#define ll long long
#define lld long double
#define pii pair < int, int >

using namespace std;

//template <typename T>
//using ordered_set = tree <T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

const int N = 3e5 + 229;
const int M = 1e9 + 7;
const ll M2 = 1e9 + 9;
const int mod = 998244353;
const int Sx[8] = {1, 1, -1, -1, -2, 2, 2, -2};
const int Sy[8] = {-2, 2, 2, -2, 1, 1, -1, -1};
const lld eps = 1e-7;
const double pi = acos(-1.0);

//mt19937 gen(chrono::system_clock::now().time_since_epoch().count());

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//    srand(time(0));
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//   freopen("input.txt", "r", stdin);
//   freopen("output.txt", "w", stdout);
#endif
    int t;
    cin >> t;
    while(t--) {
        int n, m;
        cin >> n >> m;
        if(n <= m) {
        int ans = m;
        char a[n][m];
        pair <int, int> k[m];
        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < m; ++j) {
                a[i][j] = '-';
                k[j].F = 0;k[j].S = j;
            }
        }
        int pos = m / 2 + 1;
        int cnt = n / 2;
        if(n % 2 == 0)cnt--;
        for(int z = 0; z < n; ++z) {
         if(k[pos - 1].F >= cnt)break;
         ans++;
            for(int i = 0; i < pos; ++i) {
                a[z][k[i].S] = '+';
                k[i].F++;
            }
            sort(k, k + m);

        }
        cout << ans << endl;
            for(int i = 0; i < n; ++i) {
                for(int j = 0; j < m; ++j)
                cout << a[i][j];
            cout << endl;
            }
        }
        else {
        int ans = n;
        char a[n][m];
        pair <int, int> k[n];
        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < m; ++j) {
                a[i][j] = '+';
            }
            k[i].F = 0;k[i].S = i;
        }

        int pos = n / 2 + 1;
        int cnt = m / 2;
        if(m % 2 == 0)cnt--;
        for(int z = 0; z < m; ++z) {
         if(k[pos - 1].F >=cnt)break;
         ans++;
            for(int i = 0; i < pos; ++i) {
//                    cerr <<k[i].S << endl;
                a[k[i].S][z] = '-';
                k[i].F++;
            }
//            cerr << endl;
            sort(k, k + n);
//for(int i = 0; i < n; ++i)
//            cout << k[i].F << ' ' << k[i].S << endl;
//            cout << endl;
        }
        cout << ans << endl;
            for(int i = 0; i < n; ++i) {
                for(int j = 0; j < m; ++j)
                cout << a[i][j];
            cout << endl;
            }
        }

}}
# 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 14 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 14 ms 376 KB Output is correct
4 Correct 23 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 95 ms 1468 KB Output is correct
2 Correct 43 ms 1912 KB Output is correct
3 Correct 46 ms 2064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 1376 KB Output is correct
2 Correct 42 ms 1656 KB Output is correct
3 Correct 38 ms 1400 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 14 ms 376 KB Output is correct
4 Correct 23 ms 376 KB Output is correct
5 Correct 95 ms 1468 KB Output is correct
6 Correct 43 ms 1912 KB Output is correct
7 Correct 46 ms 2064 KB Output is correct
8 Correct 68 ms 1376 KB Output is correct
9 Correct 42 ms 1656 KB Output is correct
10 Correct 38 ms 1400 KB Output is correct
11 Correct 50 ms 632 KB Output is correct
12 Correct 41 ms 1528 KB Output is correct
13 Correct 47 ms 1400 KB Output is correct
14 Correct 33 ms 1144 KB Output is correct
15 Correct 46 ms 2424 KB Output is correct
16 Correct 35 ms 1788 KB Output is correct
17 Correct 18 ms 1016 KB Output is correct