#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int n, cnt;
string s;
vector <vector <char> > a;
vector <int> all;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
cin >> s;
for (int i = 0; i < n; ++i) {
if (s[i] == '-') {
++cnt;
}
all.push_back(cnt);
if (s[i] == '+') {
--cnt;
}
}
sort(all.begin(), all.end());
all.resize(unique(all.begin(), all.end()) - all.begin());
a.resize((int)(all.size()));
for (int i = 0; i < (int)(all.size()); ++i) {
a[i].assign(n, '.');
}
cnt = 0;
for (int i = 0; i < n; ++i) {
if (s[i] == '-') {
++cnt;
}
int p = lower_bound(all.begin(), all.end(), cnt) - all.begin();
if (s[i] == '+') {
a[p][i] = '/';
} else if (s[i] == '-') {
a[p][i] = '\\';
} else {
a[p][i] = '_';
}
if (s[i] == '+') {
--cnt;
}
}
for (int i = 0; i < (int)(all.size()); ++i, cout << "\n") {
for (int j = 0; j < n; ++j) {
cout << a[i][j];
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |