제출 #1127899

#제출 시각아이디문제언어결과실행 시간메모리
1127899vusalRed-blue table (IZhO19_stones)C++20
27 / 100
30 ms1604 KiB
//mubarizvusal
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define allr(v) v.rbegin(), v.rend()
#define all(v) v.begin(), v.end()
#define mcqueen ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pii pair<int,int>
#define pb push_back
#define new int32_t
#define ts to_string
#define fi first
#define se second
#define ins insert
#define int ll
#define kub(i) i*i*i

#include <bits/stdc++.h>
using namespace std;

pair<int,int> computeAB(const vector<string> &grid) {
    int N = (int)grid.size();
    int M = (int)grid[0].size();
    // A: Satırlarda '+' sayısı '–' sayısından fazla
    // B: Sütunlarda '-' sayısı '+' sayısından fazla
    int A = 0;
    int B = 0;

    // A'yı hesapla
    for(int i=0; i<N; i++){
        int plusCount = 0, minusCount = 0;
        for(int j=0; j<M; j++){
            if(grid[i][j] == '+') plusCount++;
            else minusCount++;
        }
        if(plusCount > minusCount) A++;
    }

    // B'yi hesapla
    for(int j=0; j<M; j++){
        int plusCount = 0, minusCount = 0;
        for(int i=0; i<N; i++){
            if(grid[i][j] == '+') plusCount++;
            else minusCount++;
        }
        if(minusCount > plusCount) B++;
    }

    return {A,B};
}

new main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int T; cin >> T;
    while(T--){
        int N,M; cin >> N >> M;

        vector<vector<string>> candidates; // farklı desenler için gridleri tutacak

        // 1. Hepsi '+'
        {
            vector<string> g(N,string(M,'+'));
            candidates.push_back(g);
        }

        // 2. Hepsi '-'
        {
            vector<string> g(N,string(M,'-'));
            candidates.push_back(g);
        }

        // 3. Tümü '+' ve c sütunu '-'
        {
            vector<string> g(N,string(M,'+'));
            int c = (M-1)/2; 
            for(int col=0; col<c; col++){
                for(int i=0;i<N;i++){
                    g[i][col] = '-';
                }
            }
            candidates.push_back(g);
        }

        // 4. Tümü '-' ve r satırı '+'
        {
            vector<string> g(N,string(M,'-'));
            int r = (N-1)/2;
            for(int row=0; row<r; row++){
                for(int j=0;j<M;j++){
                    g[row][j] = '+';
                }
            }
            candidates.push_back(g);
        }

        // 5. Dama Deseni 1: (i+j) çift '+', diğer '-'
        {
            vector<string> g(N,string(M,'+'));
            for(int i=0;i<N;i++){
                for(int j=0;j<M;j++){
                    if((i+j)%2==0) g[i][j] = '+';
                    else g[i][j] = '-';
                }
            }
            candidates.push_back(g);
        }

        // 6. Dama Deseni 2: (i+j) çift '-', diğer '+'
        {
            vector<string> g(N,string(M,'+'));
            for(int i=0;i<N;i++){
                for(int j=0;j<M;j++){
                    if((i+j)%2==0) g[i][j] = '-';
                    else g[i][j] = '+';
                }
            }
            candidates.push_back(g);
        }

        // 7. Yarısı '+' satırlar, diğer yarısı '-' satırlar
        {
            vector<string> g(N,string(M,'+'));
            int half = N/2;
            // İlk half satır '+', geri kalan '-'
            // Zaten '+' doldurduk, geri kalanı '-' yapalım
            for(int i=half; i<N; i++){
                for(int j=0;j<M;j++){
                    g[i][j] = '-';
                }
            }
            candidates.push_back(g);
        }

        // 8. Yarısı '+' sütunlar, yarısı '-' sütunlar
        {
            vector<string> g(N,string(M,'+'));
            int half = M/2;
            // İlk half sütun '+', geri kalan '-'
            // Zaten '+' doldurduk, geri kalan sütunları '-'
            for(int i=0;i<N;i++){
                for(int j=half;j<M;j++){
                    g[i][j] = '-';
                }
            }
            candidates.push_back(g);
        }

        // Şimdi tüm aday gridler için A+B değerini hesapla, en iyisini seç
        int bestVal = -1;
        int bestIdx = 0;

        for(int i=0; i<(int)candidates.size(); i++){
            auto [A,B] = computeAB(candidates[i]);
            int val = A+B;
            if(val > bestVal){
                bestVal = val;
                bestIdx = i;
            }
        }

        cout << bestVal << "\n";
        for(auto &row : candidates[bestIdx]) cout << row << "\n";
    }
}

#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...