QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#639906 | #2428. Comma Sprinkler | Trentium | AC ✓ | 762ms | 121048kb | C++14 | 3.2kb | 2024-10-13 23:49:52 | 2024-10-13 23:49:52 |
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<ll, vector<ll>> string_map;
typedef gp_hash_table<ll, bool> string_set;
typedef pair<ll, bool> node;
hash<string> hasher;
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[hasher(nocom[i])].push_back(hasher(nocom[i+1]));
adp[hasher(nocom[i+1])].push_back(hasher(nocom[i]));
}
forR(i, (int) tokens.size() - 1) if(tokens[i] != "." && tokens[i] != ",") {
if(i > 0 && tokens[i-1] == ",") {
visp[hasher(tokens[i])] = true;
bfs.push_back({hasher(tokens[i]), false});
}
if(i + 1 < tokens.size() && tokens[i+1] == ",") {
bfs.push_back({hasher(tokens[i]), true});
viss[hasher(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(ll nex : ads[cur.first]) if(!visp[nex]) {
bfs.push_back({nex, false});
visp[nex] = true;
}
} else {
for(ll 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[hasher(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: 3684kb
Test #2:
score: 0
Accepted
time: 0ms
memory: 3876kb
Test #3:
score: 0
Accepted
time: 0ms
memory: 3516kb
Test #4:
score: 0
Accepted
time: 0ms
memory: 3576kb
Test #5:
score: 0
Accepted
time: 0ms
memory: 3608kb
Test #6:
score: 0
Accepted
time: 69ms
memory: 96312kb
Test #7:
score: 0
Accepted
time: 97ms
memory: 82680kb
Test #8:
score: 0
Accepted
time: 108ms
memory: 81756kb
Test #9:
score: 0
Accepted
time: 0ms
memory: 3528kb
Test #10:
score: 0
Accepted
time: 0ms
memory: 3676kb
Test #11:
score: 0
Accepted
time: 0ms
memory: 3980kb
Test #12:
score: 0
Accepted
time: 0ms
memory: 3888kb
Test #13:
score: 0
Accepted
time: 0ms
memory: 3824kb
Test #14:
score: 0
Accepted
time: 1ms
memory: 3768kb
Test #15:
score: 0
Accepted
time: 0ms
memory: 3628kb
Test #16:
score: 0
Accepted
time: 171ms
memory: 72760kb
Test #17:
score: 0
Accepted
time: 123ms
memory: 94780kb
Test #18:
score: 0
Accepted
time: 183ms
memory: 121048kb
Test #19:
score: 0
Accepted
time: 0ms
memory: 3600kb
Test #20:
score: 0
Accepted
time: 157ms
memory: 87292kb
Test #21:
score: 0
Accepted
time: 116ms
memory: 86464kb
Test #22:
score: 0
Accepted
time: 103ms
memory: 80608kb
Test #23:
score: 0
Accepted
time: 25ms
memory: 20820kb
Test #24:
score: 0
Accepted
time: 492ms
memory: 101996kb
Test #25:
score: 0
Accepted
time: 762ms
memory: 105872kb
Test #26:
score: 0
Accepted
time: 110ms
memory: 86860kb
Test #27:
score: 0
Accepted
time: 43ms
memory: 66888kb
Test #28:
score: 0
Accepted
time: 388ms
memory: 103096kb
Test #29:
score: 0
Accepted
time: 0ms
memory: 7656kb
Test #30:
score: 0
Accepted
time: 0ms
memory: 3876kb
Test #31:
score: 0
Accepted
time: 2ms
memory: 7412kb
Test #32:
score: 0
Accepted
time: 8ms
memory: 7516kb
Test #33:
score: 0
Accepted
time: 0ms
memory: 3700kb
Test #34:
score: 0
Accepted
time: 1ms
memory: 3708kb
Test #35:
score: 0
Accepted
time: 0ms
memory: 3648kb
Test #36:
score: 0
Accepted
time: 0ms
memory: 3880kb
Test #37:
score: 0
Accepted
time: 0ms
memory: 3584kb
Test #38:
score: 0
Accepted
time: 0ms
memory: 3884kb
Test #39:
score: 0
Accepted
time: 0ms
memory: 3892kb
Test #40:
score: 0
Accepted
time: 0ms
memory: 3544kb
Test #41:
score: 0
Accepted
time: 10ms
memory: 10404kb
Test #42:
score: 0
Accepted
time: 6ms
memory: 9940kb
Test #43:
score: 0
Accepted
time: 5ms
memory: 10328kb
Test #44:
score: 0
Accepted
time: 7ms
memory: 9960kb
Test #45:
score: 0
Accepted
time: 10ms
memory: 10304kb
Test #46:
score: 0
Accepted
time: 10ms
memory: 10040kb
Test #47:
score: 0
Accepted
time: 45ms
memory: 37132kb
Test #48:
score: 0
Accepted
time: 45ms
memory: 38180kb
Test #49:
score: 0
Accepted
time: 36ms
memory: 37260kb
Test #50:
score: 0
Accepted
time: 28ms
memory: 30372kb
Test #51:
score: 0
Accepted
time: 24ms
memory: 30084kb
Test #52:
score: 0
Accepted
time: 19ms
memory: 30004kb
Test #53:
score: 0
Accepted
time: 69ms
memory: 61924kb
Test #54:
score: 0
Accepted
time: 80ms
memory: 60492kb
Test #55:
score: 0
Accepted
time: 64ms
memory: 60336kb
Test #56:
score: 0
Accepted
time: 69ms
memory: 61500kb
Test #57:
score: 0
Accepted
time: 59ms
memory: 59356kb
Test #58:
score: 0
Accepted
time: 59ms
memory: 59512kb
Test #59:
score: 0
Accepted
time: 0ms
memory: 3636kb
Test #60:
score: 0
Accepted
time: 4ms
memory: 9124kb
Test #61:
score: 0
Accepted
time: 4ms
memory: 8036kb
Test #62:
score: 0
Accepted
time: 0ms
memory: 3580kb