QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#380746 | #2428. Comma Sprinkler | ckiseki# | AC ✓ | 553ms | 63108kb | C++20 | 2.2kb | 2024-04-07 11:06:04 | 2024-04-07 11:06:05 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
#ifdef CKISEKI
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << " safe\n"
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
void debug_(auto s, auto ...a) {
cerr << "\e[1;32m(" << s << ") = (";
int f = 0;
(..., (cerr << (f++ ? ", " : "") << a));
cerr << ")\e[0m\n";
}
#include <experimental/iterator>
void orange_(auto s, auto L, auto R) {
cerr << "\e[1;33m[ " << s << " ] = [ ";
using namespace experimental;
copy(L, R, make_ostream_joiner(cerr, ", "));
cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
vector<string> v, u;
string s;
while (cin >> s) {
v.push_back(s);
if (s.back() == ',' or s.back() == '.') {
s = s.substr(0, s.size() - 1);
}
u.push_back(s);
}
map<string, vector<int>> after, before;
set<string> vis_after, vis_before;
for (size_t i = 0; i < v.size(); i++) {
after[u[i]].push_back(i);
}
for (size_t i = 0; i + 1 < v.size(); i++) {
before[u[i + 1]].push_back(i);
}
queue<pair<string, int>> q;
for (size_t i = 0; i < v.size(); i++) {
if (v[i].back() == ',') {
if (!vis_after.count(u[i])) {
vis_after.insert(u[i]);
q.emplace(u[i], 0);
}
if (!vis_before.count(u[i + 1])) {
vis_before.insert(u[i + 1]);
q.emplace(u[i + 1], 1);
}
}
}
auto add_comma = [&](int i) {
if (v[i].back() != ',' && v[i].back() != '.') {
v[i] += ',';
if (!vis_after.count(u[i])) {
vis_after.insert(u[i]);
q.emplace(u[i], 0);
}
if (!vis_before.count(u[i + 1])) {
vis_before.insert(u[i + 1]);
q.emplace(u[i + 1], 1);
}
}
};
while (!q.empty()) {
auto [t, dir] = q.front(); q.pop();
if (dir == 0) {
for (int pos : after[t]) {
add_comma(pos);
}
} else {
for (int pos : before[t]) {
add_comma(pos);
}
}
}
for (size_t i = 0; i < v.size(); i++) {
cout << v[i] << (i+1==v.size() ? '\n' : ' ');
}
return 0;
}
Details
Test #1:
score: 100
Accepted
time: 0ms
memory: 3804kb
Test #2:
score: 0
Accepted
time: 0ms
memory: 3632kb
Test #3:
score: 0
Accepted
time: 0ms
memory: 3760kb
Test #4:
score: 0
Accepted
time: 0ms
memory: 3840kb
Test #5:
score: 0
Accepted
time: 0ms
memory: 3604kb
Test #6:
score: 0
Accepted
time: 36ms
memory: 41264kb
Test #7:
score: 0
Accepted
time: 156ms
memory: 48616kb
Test #8:
score: 0
Accepted
time: 143ms
memory: 50032kb
Test #9:
score: 0
Accepted
time: 0ms
memory: 3528kb
Test #10:
score: 0
Accepted
time: 0ms
memory: 3848kb
Test #11:
score: 0
Accepted
time: 1ms
memory: 3864kb
Test #12:
score: 0
Accepted
time: 0ms
memory: 3764kb
Test #13:
score: 0
Accepted
time: 1ms
memory: 3668kb
Test #14:
score: 0
Accepted
time: 0ms
memory: 3672kb
Test #15:
score: 0
Accepted
time: 0ms
memory: 3624kb
Test #16:
score: 0
Accepted
time: 158ms
memory: 34608kb
Test #17:
score: 0
Accepted
time: 272ms
memory: 38900kb
Test #18:
score: 0
Accepted
time: 553ms
memory: 58248kb
Test #19:
score: 0
Accepted
time: 0ms
memory: 3796kb
Test #20:
score: 0
Accepted
time: 484ms
memory: 61360kb
Test #21:
score: 0
Accepted
time: 290ms
memory: 56252kb
Test #22:
score: 0
Accepted
time: 229ms
memory: 50844kb
Test #23:
score: 0
Accepted
time: 17ms
memory: 14148kb
Test #24:
score: 0
Accepted
time: 433ms
memory: 61760kb
Test #25:
score: 0
Accepted
time: 390ms
memory: 63108kb
Test #26:
score: 0
Accepted
time: 265ms
memory: 51016kb
Test #27:
score: 0
Accepted
time: 150ms
memory: 40316kb
Test #28:
score: 0
Accepted
time: 359ms
memory: 56836kb
Test #29:
score: 0
Accepted
time: 4ms
memory: 8192kb
Test #30:
score: 0
Accepted
time: 0ms
memory: 3608kb
Test #31:
score: 0
Accepted
time: 3ms
memory: 5896kb
Test #32:
score: 0
Accepted
time: 0ms
memory: 11228kb
Test #33:
score: 0
Accepted
time: 0ms
memory: 3800kb
Test #34:
score: 0
Accepted
time: 1ms
memory: 3652kb
Test #35:
score: 0
Accepted
time: 0ms
memory: 3616kb
Test #36:
score: 0
Accepted
time: 0ms
memory: 3608kb
Test #37:
score: 0
Accepted
time: 0ms
memory: 3828kb
Test #38:
score: 0
Accepted
time: 0ms
memory: 3608kb
Test #39:
score: 0
Accepted
time: 0ms
memory: 3604kb
Test #40:
score: 0
Accepted
time: 0ms
memory: 3608kb
Test #41:
score: 0
Accepted
time: 11ms
memory: 6592kb
Test #42:
score: 0
Accepted
time: 11ms
memory: 6652kb
Test #43:
score: 0
Accepted
time: 11ms
memory: 6652kb
Test #44:
score: 0
Accepted
time: 7ms
memory: 6576kb
Test #45:
score: 0
Accepted
time: 7ms
memory: 6588kb
Test #46:
score: 0
Accepted
time: 7ms
memory: 6768kb
Test #47:
score: 0
Accepted
time: 81ms
memory: 18656kb
Test #48:
score: 0
Accepted
time: 83ms
memory: 18736kb
Test #49:
score: 0
Accepted
time: 95ms
memory: 18416kb
Test #50:
score: 0
Accepted
time: 61ms
memory: 16324kb
Test #51:
score: 0
Accepted
time: 62ms
memory: 15420kb
Test #52:
score: 0
Accepted
time: 58ms
memory: 15460kb
Test #53:
score: 0
Accepted
time: 157ms
memory: 28660kb
Test #54:
score: 0
Accepted
time: 166ms
memory: 28772kb
Test #55:
score: 0
Accepted
time: 184ms
memory: 28812kb
Test #56:
score: 0
Accepted
time: 164ms
memory: 27600kb
Test #57:
score: 0
Accepted
time: 153ms
memory: 27572kb
Test #58:
score: 0
Accepted
time: 149ms
memory: 28708kb
Test #59:
score: 0
Accepted
time: 0ms
memory: 3560kb
Test #60:
score: 0
Accepted
time: 0ms
memory: 6888kb
Test #61:
score: 0
Accepted
time: 3ms
memory: 5680kb
Test #62:
score: 0
Accepted
time: 1ms
memory: 3764kb