Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: Nuttykub

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

Language: cpp

Time: 0.004 second

Submitted On: 2026-10-06 10:29:42

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

int main() {
    string s;
    int n;
    cin >> s >> n;

    int m = s.size();                 // number of diamonds (one per character)
    int h = 2*n+1;                // grid height
    int stride =2*n-1;           // distance between neighbouring diamond centres
    int w = 2*n+1+(m-1)*stride;  // equals your: 2n + m + (n-1)*2*(m-1)

    vector<string> g(h, string(w, '.'));

    for (int i = 0; i < h; i++) {
        int half = min(i, 2 * n - i); // half-width of the diamond on this row
        for (int c = 0; c < m; c++) {
            int center = c * stride + n;
            g[i][center - half] = s[c];
            g[i][center + half] = s[c];
        }
    }

    for (auto &row : g) cout << row << '\n';
}