Submission #344369

#TimeUsernameProblemLanguageResultExecution timeMemory
344369koketsuRed-blue table (IZhO19_stones)C++14
100 / 100
72 ms5328 KiB
#include <bits/stdc++.h>
#define pb push_back
#define LL long long
#define Kultivator ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const LL Mxn = 1e6 + 7;
const LL Mod = 1e9 + 7;
const LL Inf = 1e14 + 7;

int N, M;

int S[1001], A[1001][1001];

void Solve(){
    int Ans = 0;
    bool Inv = false;
    if(M < N){
        swap(M, N);
        Inv = true;
    }
    Ans += M;
    //cout << N << ' ' << M;/
    for(int i = 0; i < M; i++){
        S[i] = -N;
    }
    for(int i = 0; i < N; i++){
        vector <pair <int, int>> V;
        for(int j = 0; j < M; j++){
            A[i][j] = false;
            V.pb({S[j], j});
        }
        sort(V.begin(), V.  end());
        bool Check = false;
        for(int j = 0; j < (M / 2) + 1; j++){
            if(V[j].first + 2 >= 0) Check = true;
        }
        if(!Check){
            Ans++;
            for(int j = 0; j < (M / 2) + 1; j++){
                S[V[j].second] += 2;
                A[i][V[j].second] = true;
            }
        }
    }
    cout << Ans << '\n';
    if(!Inv){
        for(int i = 0; i < N; i++){
            for(int j = 0; j < M; j++){
                if(!A[i][j]) cout << '-';
                else cout << '+';
            }
            cout << '\n';
        }
    } else {
        for(int i = 0; i < M; i++){
            for(int j = 0; j < N; j++){
                if(A[j][i]) cout << '-';
                else cout << '+';
            }
            cout << '\n';
        }
    }
}

int main() {
    Kultivator;
    int tt;
    cin >> tt;
    while(tt--){
        cin >> N >> M;
        Solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...