Submission #498791

# Submission time Handle Problem Language Result Execution time Memory
498791 2021-12-26T11:03:45 Z Shavkatjon Red-blue table (IZhO19_stones) C++14
100 / 100
28 ms 2200 KB
#include <bits/stdc++.h>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define int long long
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) sort(x.begin(), x.end())
#define rall(x) sort(x.rbegin(), x.rend())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int gcd(int a, int b) {
    return b ? gcd (b, a % b) : a;
}

string reverse(string s){
    int n = s.length();
    for (int i = 0; i < (n+1) / 2; i++) swap(s[i], s[n - i - 1]);
    return s;
}


int binpow (int a, int n) {
    if (n == 0)
        return 1LL;
    if (n % 2 == 1)
        return ((binpow (a, n-1)%MOD) * 1LL * a)%MOD;
    else {
        int b = binpow (a, n/2)%MOD;
        return (b * b)%MOD;
    }
}

//void swap(int &a, int &b){
//    b = (a+b) - (a=b);
//}

void solve(){
    int n, m, swaped = 0;
    cin >> n >> m;
    char red = '+', blue = '-';
    if(n < m){
        swap(n, m);
        swap(red, blue);
        swaped = 1;
    }
    char a[n][m];
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < m; ++j)
        {
            a[i][j] = red;
        }
    }
    int ans = n, temp = 0, w = 0;
    for(int i = 0; i < (m - 1) / 2; i++){
        for (int j = 0; j < n; ++j)
        {
            a[j][w] = blue;
            temp++;
            if(temp == (n / 2) + 1) ans++, w++, temp = 0;
        }
    }
    cout << ans << "\n";
    if(swaped){
        for (int i = 0; i < m; ++i)
        {
            for (int j = 0; j < n; ++j)
            {
                cout << a[j][i];
            }
            cout << "\n";
        }
    }else{
        for (int i = 0; i < n; ++i)
        {
            for (int j = 0; j < m; ++j)
            {
                cout << a[i][j];
            }
            cout << "\n";
        }
    }
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    cin >> t;
    while(t--){
        solve();
        cout << "\n";
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 1308 KB Output is correct
2 Correct 21 ms 1764 KB Output is correct
3 Correct 22 ms 1732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 1220 KB Output is correct
2 Correct 22 ms 1584 KB Output is correct
3 Correct 21 ms 1328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 28 ms 1308 KB Output is correct
6 Correct 21 ms 1764 KB Output is correct
7 Correct 22 ms 1732 KB Output is correct
8 Correct 27 ms 1220 KB Output is correct
9 Correct 22 ms 1584 KB Output is correct
10 Correct 21 ms 1328 KB Output is correct
11 Correct 6 ms 460 KB Output is correct
12 Correct 21 ms 1476 KB Output is correct
13 Correct 22 ms 1316 KB Output is correct
14 Correct 15 ms 1100 KB Output is correct
15 Correct 28 ms 2200 KB Output is correct
16 Correct 17 ms 1740 KB Output is correct
17 Correct 9 ms 948 KB Output is correct