제출 #1127894

#제출 시각아이디문제언어결과실행 시간메모리
1127894vusalRed-blue table (IZhO19_stones)C++20
0 / 100
9 ms1348 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

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

        int floor_M_half = M / 2;
        int floor_N_half = N / 2;
        int floor_N_half_plus_one = floor_N_half + 1;

        long long B1 = (long long)(N) * floor_M_half / floor_N_half_plus_one;
        B1 = min((long long)B1, (long long)M);
        long long Total1 = (long long)N + B1;

        long long B2 = (long long)(N) * M / floor_N_half_plus_one;
        B2 = min((long long)B2, (long long)M);
        long long Total2 = B2;

        if(Total1 > Total2){
            vector<string> grid(N, string(M, '+'));
            vector<int> row_dashes(N, 0);
            int current_row =0;
            for(int c=0; c < B1; c++){
                for(int d=0; d < floor_N_half_plus_one; d++){
                    // Find the next row that can accept a '-'
                    while(row_dashes[current_row] >= floor_M_half && row_dashes[current_row] < floor_M_half +1){
                        current_row = (current_row +1 ) % N;
                    }
                    grid[current_row][c] = '-';
                    row_dashes[current_row]++;
                    current_row = (current_row +1 ) % N;
                }
            }
            cout << (N + B1) << "\n";
            for(int i=0; i < N; i++) cout << grid[i] << "\n";
        }
        else{
            vector<string> grid(N, string(M, '+'));
            int current_row =0;
            for(int c=0; c < B2; c++){
                for(int d=0; d < floor_N_half_plus_one; d++){
                    grid[current_row][c] = '-';
                    current_row = (current_row +1 ) % N;
                }
            }
            // A=0, B=B2
            cout << B2 << "\n";
            for(int i=0; i < N; i++) cout << grid[i] << "\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...