Submission

Status:

PPPPP

Subtask/Task Score:

100/100

Score: 100

User: fillhavertz

Problemset: กังหันสี่ทิศ

Language: cpp

Time: 0.003 second

Submitted On: 2025-10-05 16:02:49

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath> // For std::abs

using namespace std;

// The maximum value for n to meet the 1-second limit is quite large, 
// so the logic must be O(N^2) total output size, and O(N) work per row.

int main() {
    // These lines are already great for I/O performance
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    if (!(cin >> n)) return 0; // Handle invalid input

    // The total height of the pattern is (2*n) - 1 rows
    int total_rows = (2 * n) - 1;
    // The width of a single character/star pattern is 2*n characters
    int half_width = 2 * n;

    // Outer loop iterates through each row
    for (int i = 0; i < total_rows; ++i) {
        // We'll build the entire line string for both the character and '*' part
        string line;
        line.reserve(2 * half_width); // Pre-allocate space for efficiency

        // 1. Calculate the character to print for the current row
        // The center row is at i = n-1, where abs(i + 1 - n) = 0, giving 'A'
        // abs(i + 1 - n) gives the distance from the center row, which determines the character
        char out_char = 'A' + abs(i + 1 - n);
        
        // The condition for drawing the pattern is:
        // k == i (Left diagonal) OR k + i == (2*n)-2 (Right diagonal)
        
        // --- Part 1: Character Pattern ---
        for (int k = 0; k < half_width; ++k) {
            if ((k == i) || (k + i == total_rows - 1)) {
                line += out_char;
            } else {
                line += ' ';
            }
        }

        // --- Part 2: Star Pattern ---
        for (int k = 0; k < half_width; ++k) {
            if ((k == i) || (k + i == total_rows - 1)) {
                line += '*';
            } else {
                line += ' ';
            }
        }
        
        // Print the entire line at once
        cout << line << '\n';
    }

    // Since we used '\n' (which is generally better than endl), we don't need a final flush.
    
    return 0;
}