QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#639894 | #2428. Comma Sprinkler | Trentium | AC ✓ | 6467ms | 170732kb | C++14 | 3.1kb | 2024-10-13 23:32:51 | 2024-10-13 23:32:53 |
Judging History
answer
#include "bits/extc++.h"
using namespace std;
using namespace __gnu_pbds;
#define forR(i, x) for(int i = 0; i < (x); ++i)
#define REP(i, a, b) for(int i =(a); i < (b); ++i)
#define boost() cin.sync_with_stdio(0); cin.tie(0)
typedef long long ll;
typedef vector<int> vi;
typedef gp_hash_table<string, vector<string>> string_map;
typedef gp_hash_table<string, bool> string_set;
typedef pair<string, bool> node;
signed main(){
boost();
vector<string> tokens;
string s; getline(cin, s);
int ci = 0;
bool addLast = false;
while(ci < s.size()){
if(s[ci] == ' ') {
addLast = false;
++ci;
} else if(s[ci] == ',') {
tokens.push_back(",");
addLast = false;
ci += 2;
} else if(s[ci] == '.') {
tokens.push_back(".");
if(ci + 1 == s.size()) ++ci;
else ci += 2;
addLast = false;
} else {
if(!addLast) {
tokens.emplace_back();
tokens.back().push_back(s[ci]);
addLast = true;
++ci;
} else {
tokens.back().push_back(s[ci]);
++ci;
}
}
}
// for(string i : tokens) cout << i << '\n';
vector<string> nocom;
for(string i : tokens) if(i != ",") nocom.push_back(i);
string_map ads;
string_map adp;
string_set viss;
string_set visp;
vector<node> bfs;
forR(i, (int) nocom.size() - 1) if(nocom[i] != "." && nocom[i+1] != ".") {
ads[nocom[i]].push_back(nocom[i+1]);
adp[nocom[i+1]].push_back(nocom[i]);
}
forR(i, (int) tokens.size() - 1) if(tokens[i] != "." && tokens[i] != ",") {
if(i > 0 && tokens[i-1] == ",") {
visp[tokens[i]] = true;
bfs.push_back({tokens[i], false});
}
if(i + 1 < tokens.size() && tokens[i+1] == ",") {
bfs.push_back({tokens[i], true});
viss[tokens[i]] = true;
}
}
int tot = 0;
while(!bfs.empty()){
node cur = bfs.back();
bfs.pop_back();
++tot;
assert(tot < 2 * tokens.size() + 10);
if(cur.second) {
for(string nex : ads[cur.first]) if(!visp[nex]) {
bfs.push_back({nex, false});
visp[nex] = true;
}
} else {
for(string nex : adp[cur.first]) if(!viss[nex]) {
bfs.push_back({nex, true});
viss[nex] = true;
}
}
}
vector<string> toPrint;
forR(ci, nocom.size()) {
string i = nocom[ci];
if(i == ".") toPrint.push_back(". ");
else {
if(visp[i] && !toPrint.empty() && toPrint.back() != ", " && toPrint.back() != ". ") {
toPrint.push_back(", ");
} else if(!toPrint.empty() && toPrint.back() != ", " && toPrint.back() != ". ") {
toPrint.push_back(" ");
}
toPrint.push_back(i);
}
}
for(string i : toPrint) cout << i;
cout << '\n';
}
Details
Test #1:
score: 100
Accepted
time: 0ms
memory: 3656kb
Test #2:
score: 0
Accepted
time: 0ms
memory: 3684kb
Test #3:
score: 0
Accepted
time: 0ms
memory: 3676kb
Test #4:
score: 0
Accepted
time: 0ms
memory: 3592kb
Test #5:
score: 0
Accepted
time: 0ms
memory: 3868kb
Test #6:
score: 0
Accepted
time: 96ms
memory: 102424kb
Test #7:
score: 0
Accepted
time: 154ms
memory: 123592kb
Test #8:
score: 0
Accepted
time: 180ms
memory: 112328kb
Test #9:
score: 0
Accepted
time: 0ms
memory: 3896kb
Test #10:
score: 0
Accepted
time: 0ms
memory: 3692kb
Test #11:
score: 0
Accepted
time: 1ms
memory: 3824kb
Test #12:
score: 0
Accepted
time: 0ms
memory: 3652kb
Test #13:
score: 0
Accepted
time: 1ms
memory: 3796kb
Test #14:
score: 0
Accepted
time: 1ms
memory: 3700kb
Test #15:
score: 0
Accepted
time: 0ms
memory: 3648kb
Test #16:
score: 0
Accepted
time: 775ms
memory: 118344kb
Test #17:
score: 0
Accepted
time: 505ms
memory: 121692kb
Test #18:
score: 0
Accepted
time: 425ms
memory: 170732kb
Test #19:
score: 0
Accepted
time: 0ms
memory: 3880kb
Test #20:
score: 0
Accepted
time: 295ms
memory: 132920kb
Test #21:
score: 0
Accepted
time: 228ms
memory: 114948kb
Test #22:
score: 0
Accepted
time: 223ms
memory: 110712kb
Test #23:
score: 0
Accepted
time: 73ms
memory: 33252kb
Test #24:
score: 0
Accepted
time: 3491ms
memory: 134924kb
Test #25:
score: 0
Accepted
time: 6467ms
memory: 149200kb
Test #26:
score: 0
Accepted
time: 143ms
memory: 106912kb
Test #27:
score: 0
Accepted
time: 69ms
memory: 70524kb
Test #28:
score: 0
Accepted
time: 2563ms
memory: 149128kb
Test #29:
score: 0
Accepted
time: 13ms
memory: 12504kb
Test #30:
score: 0
Accepted
time: 0ms
memory: 3848kb
Test #31:
score: 0
Accepted
time: 0ms
memory: 8148kb
Test #32:
score: 0
Accepted
time: 23ms
memory: 14536kb
Test #33:
score: 0
Accepted
time: 0ms
memory: 3648kb
Test #34:
score: 0
Accepted
time: 1ms
memory: 3792kb
Test #35:
score: 0
Accepted
time: 1ms
memory: 3656kb
Test #36:
score: 0
Accepted
time: 0ms
memory: 3596kb
Test #37:
score: 0
Accepted
time: 0ms
memory: 3652kb
Test #38:
score: 0
Accepted
time: 1ms
memory: 3648kb
Test #39:
score: 0
Accepted
time: 0ms
memory: 3852kb
Test #40:
score: 0
Accepted
time: 0ms
memory: 3580kb
Test #41:
score: 0
Accepted
time: 12ms
memory: 12516kb
Test #42:
score: 0
Accepted
time: 9ms
memory: 12676kb
Test #43:
score: 0
Accepted
time: 11ms
memory: 12184kb
Test #44:
score: 0
Accepted
time: 16ms
memory: 12536kb
Test #45:
score: 0
Accepted
time: 11ms
memory: 12592kb
Test #46:
score: 0
Accepted
time: 7ms
memory: 12448kb
Test #47:
score: 0
Accepted
time: 65ms
memory: 53020kb
Test #48:
score: 0
Accepted
time: 74ms
memory: 52496kb
Test #49:
score: 0
Accepted
time: 93ms
memory: 52228kb
Test #50:
score: 0
Accepted
time: 59ms
memory: 37136kb
Test #51:
score: 0
Accepted
time: 58ms
memory: 37104kb
Test #52:
score: 0
Accepted
time: 62ms
memory: 38000kb
Test #53:
score: 0
Accepted
time: 179ms
memory: 86356kb
Test #54:
score: 0
Accepted
time: 132ms
memory: 86044kb
Test #55:
score: 0
Accepted
time: 175ms
memory: 84536kb
Test #56:
score: 0
Accepted
time: 97ms
memory: 81456kb
Test #57:
score: 0
Accepted
time: 115ms
memory: 80136kb
Test #58:
score: 0
Accepted
time: 110ms
memory: 81468kb
Test #59:
score: 0
Accepted
time: 0ms
memory: 3880kb
Test #60:
score: 0
Accepted
time: 7ms
memory: 10048kb
Test #61:
score: 0
Accepted
time: 5ms
memory: 10148kb
Test #62:
score: 0
Accepted
time: 0ms
memory: 3620kb