Submission

Status:

PPxPP

Subtask/Task Score:

80/100

Score: 80

User: Newton4566

Problemset: หินงอก

Language: cpp

Time: 0.002 second

Submitted On: 2026-10-06 21:13:03

#include <iostream>
using namespace std;

int main() {
    int n;
    int len[20];
    string canvas[15];               // normal array: one string per row

    cin >> n;                        // number of stalactites (<= 20)

    int totalWidth = 0, maxLen = 0;
    for (int i = 0; i < n; i++) {
        cin >> len[i];               // length of each stalactite (<= 15)
        totalWidth += 2 * len[i];
        if (len[i] > maxLen) maxLen = len[i];
    }

    // each row is a string of spaces, as wide as the whole picture
    for (int r = 0; r < maxLen; r++)
        canvas[r] = string(totalWidth, ' ');

    // draw each stalactite
    int offset = 0;
    for (int k = 0; k < n; k++) {
        int L = len[k];
        for (int i = 1; i <= L; i++) {
            canvas[i - 1][offset + i - 1]     = '\\';   // left side
            canvas[i - 1][offset + 2 * L - i] = '/';    // right side
        }
        offset += 2 * L;             // next stalactite starts here
    }

    // print row by row, trimming trailing spaces
    for (int r = 0; r < maxLen; r++) {
        int last = totalWidth - 1;
        while (last >= 0 && canvas[r][last] == ' ')
            last--;
        cout << canvas[r].substr(0, last + 1) << endl;
    }

    return 0;
}