Submission
Status:
PPPPP
Subtask/Task Score:
100/100
Score: 100
User: fillhavertz
Problemset: หินงอก
Language: cpp
Time: 0.003 second
Submitted On: 2025-10-05 11:41:50
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, sum = 0, maxh = 0;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i] * 2;
if (a[i] > maxh) maxh = a[i];
}
// Pre-allocate one line of sufficient length
int width = 0;
for (int x : a) width += x * 2;
for (int col = 0; col < maxh; col++) {
string line(width, ' ');
int offset = 0;
for (int i = 0; i < n; i++) {
int h = a[i];
int len = h * 2;
// Place slashes only where needed
if (col < h) line[offset + col] = '\\';
if (col < h) line[offset + (len - col - 1)] = '/';
offset += len;
}
cout << line << '\n';
}
}