Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: eefirefire

Problemset: ห่วงโซ่ (Chain)

Language: cpp

Time: 0.004 second

Submitted On: 2026-09-20 08:11:30

#include <iostream>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    string s;
    if (!(cin >> s)) return 0;

    int h;
    if (!(cin >> h)) return 0;

    int n = s.length();
    int H = 2 * h + 1;
    int W = (n == 0) ? 0 : (2 * h + (n - 1) * (2 * h - 1) + 1);

    vector<string> grid(H, string(W, '.'));

    for (int k = 0; k < n; k++) {
        char ch = s[k];
        int center_c = h + k * (2 * h - 1);
        int center_r = h;

        for (int dr = -h; dr <= h; dr++) {
            int dc = h - abs(dr);
            int r = center_r + dr;

            grid[r][center_c - dc] = ch;
            grid[r][center_c + dc] = ch;
        }
    }

    for (int r = 0; r < H; r++) {
        cout << grid[r] << '\n';
    }

    return 0;
}