QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#639859 | #2428. Comma Sprinkler | Trentium | TL | 3900ms | 124340kb | C++14 | 2.8kb | 2024-10-13 23:18:06 | 2024-10-13 23:18:06 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
#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 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);
map<node, vector<node>> adj;
set<node> vis;
vector<node> bfs;
forR(i, (int) nocom.size() - 1) if(nocom[i] != "." && nocom[i+1] != ".") {
adj[{nocom[i], true}].push_back({nocom[i+1], false});
adj[{nocom[i+1], false}].push_back({nocom[i], true});
}
forR(i, (int) tokens.size() - 1) if(tokens[i] != "." && tokens[i] != ",") {
if(i > 0 && tokens[i-1] == ",") {
bfs.push_back({tokens[i], false});
vis.insert({tokens[i], false});
}
if(i + 1 < tokens.size() && tokens[i+1] == ",") {
bfs.push_back({tokens[i], true});
vis.insert({tokens[i], true});
}
}
int tot = 0;
while(!bfs.empty()){
node cur = bfs.back();
bfs.pop_back();
++tot;
assert(tot < 2 * tokens.size() + 10);
for(node nex : adj[cur]) if(!vis.count(nex)) {
vis.insert(nex);
bfs.push_back(nex);
}
}
vector<string> toPrint;
forR(ci, nocom.size()) {
string i = nocom[ci];
if(i == ".") toPrint.push_back(". ");
else {
if(vis.count({i, false}) && !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: 3636kb
Test #2:
score: 0
Accepted
time: 0ms
memory: 3556kb
Test #3:
score: 0
Accepted
time: 0ms
memory: 3548kb
Test #4:
score: 0
Accepted
time: 0ms
memory: 3572kb
Test #5:
score: 0
Accepted
time: 0ms
memory: 3608kb
Test #6:
score: 0
Accepted
time: 129ms
memory: 123820kb
Test #7:
score: 0
Accepted
time: 236ms
memory: 86728kb
Test #8:
score: 0
Accepted
time: 234ms
memory: 84148kb
Test #9:
score: 0
Accepted
time: 0ms
memory: 3776kb
Test #10:
score: 0
Accepted
time: 0ms
memory: 3532kb
Test #11:
score: 0
Accepted
time: 1ms
memory: 3672kb
Test #12:
score: 0
Accepted
time: 0ms
memory: 3848kb
Test #13:
score: 0
Accepted
time: 1ms
memory: 3832kb
Test #14:
score: 0
Accepted
time: 1ms
memory: 3732kb
Test #15:
score: 0
Accepted
time: 0ms
memory: 3632kb
Test #16:
score: 0
Accepted
time: 3900ms
memory: 124340kb
Test #17:
score: 0
Accepted
time: 2528ms
memory: 105640kb
Test #18:
score: 0
Accepted
time: 1827ms
memory: 115624kb
Test #19:
score: 0
Accepted
time: 0ms
memory: 3856kb
Test #20:
score: 0
Accepted
time: 1191ms
memory: 98436kb
Test #21:
score: 0
Accepted
time: 544ms
memory: 88912kb
Test #22:
score: 0
Accepted
time: 379ms
memory: 77912kb
Test #23:
score: 0
Accepted
time: 26ms
memory: 22164kb
Test #24:
score: -100
Time Limit Exceeded