QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#218114 | #2428. Comma Sprinkler | Kronos# | AC ✓ | 597ms | 44272kb | C++17 | 4.8kb | 2023-10-17 18:39:26 | 2023-10-17 18:39:26 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
struct debug {
#define contPrint { *this << "["; \
int f = 0; for(auto it : x) { *this << (f?", ":""); *this << it; f = 1;} \
*this << "]"; return *this;}
~debug(){cerr << endl;}
template<class c> debug& operator<<(c x) {cerr << x; return *this;}
template<class c, class d>
debug& operator<<(pair<c, d> x) {*this << "(" << x.first << ", " << x.second << ")";
return *this;}
template<class c> debug& operator<<(vector<c> x) contPrint;
template<class c> debug& operator<<(deque<c> x) contPrint;
template<class c> debug& operator<<(set<c> x) contPrint;
template<class c> debug& operator<<(multiset<c> x) contPrint;
template<class c, class d> debug& operator<<(map<c, d> x) contPrint;
template<class c, class d> debug& operator<<(unordered_map<c, d> x) contPrint;
#undef contPrint
};
#define dbg(x) "[" << #x << ": " << x << "] "
#define Wa() cerr << "[LINE: " << __LINE__ << "] -> "; debug() <<
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
const int N = 1e6 + 6;
char ch[N];
int main()
{
map<string, vector<int>> pos;
vector<string> v;
while(scanf("%s", ch) != EOF) {
string s = ch;
if(s.back() == '.' || s.back() == ',') s.pop_back();
pos[s].push_back(v.size());
v.push_back(string(ch));
}
int sz = (int)v.size();
queue<pair<string, int>> q;
set<string> bef, aft;
for(int i = 0; i < sz; i++) {
if(i) {
if(v[i-1].back() == ',') {
if(v[i].back() == '.') {
v[i].pop_back();
if(bef.find(v[i]) == bef.end()) {
bef.insert(v[i]);
q.push({v[i], 0});
}
v[i].push_back('.');
} else if (v[i].back() == ','){
v[i].pop_back();
if(bef.find(v[i]) == bef.end()) {
bef.insert(v[i]);
q.push({v[i], 0});
}
v[i].push_back(',');
} else {
if(bef.find(v[i]) == bef.end()) {
bef.insert(v[i]);
q.push({v[i], 0});
}
}
}
}
if(v[i].back() == ',') {
v[i].pop_back();
if(aft.find(v[i]) == aft.end()) {
aft.insert(v[i]);
q.push({v[i], 1});
}
v[i].push_back(',');
}
}
while(!q.empty()) {
auto [cur, t] = q.front(); q.pop();
// Wa() dbg(cur) dbg(t) dbg(pos[cur]);
if(t == 0) {
for(int p : pos[cur]) {
if(p) {
char c = '#';
if(v[p-1].back() == '.' || v[p-1].back() ==',') {
c = v[p-1].back();
v[p-1].pop_back();
}
if(c == '#' && aft.find(v[p-1]) == aft.end()) {
q.push({v[p-1], 1});
aft.insert(v[p-1]);
}
if(c != '#') {
v[p-1].push_back(c);
}
}
}
}
if(t == 1) {
for(int p : pos[cur]) {
if(p < sz-1) {
if(v[p].back() == '.') continue;
char c = '#';
if(v[p+1].back() == '.' || v[p+1].back() == ',') {
c = v[p+1].back();
v[p+1].pop_back();
}
if(bef.find(v[p+1]) == bef.end()) {
q.push({v[p+1], 0});
bef.insert(v[p+1]);
}
if(c != '#') {
v[p+1].push_back(c);
}
}
}
}
}
// Wa() dbg(bef) dbg(aft);
for(int i = 0; i < sz; i++) {
auto s = v[i];
if(s.back() == ',' || s.back() == '.') s.pop_back();
if(aft.find(s) != aft.end()) {
if(v[i].back() != '.' and v[i].back() != ',') {
v[i] += ',';
}
}
if(i) {
if(bef.find(s) != bef.end()) {
if(v[i-1].back() != '.' && v[i-1].back() != ',') {
v[i-1] += ',';
}
}
}
}
// Wa() dbg(aft) dbg(bef);
for(int i = 0; i < sz; i++) {
if(i) printf(" ");
printf("%s", v[i].c_str());
}
puts("");
}
Details
Test #1:
score: 100
Accepted
time: 1ms
memory: 3668kb
Test #2:
score: 0
Accepted
time: 0ms
memory: 3724kb
Test #3:
score: 0
Accepted
time: 0ms
memory: 3620kb
Test #4:
score: 0
Accepted
time: 0ms
memory: 3612kb
Test #5:
score: 0
Accepted
time: 0ms
memory: 3672kb
Test #6:
score: 0
Accepted
time: 71ms
memory: 22848kb
Test #7:
score: 0
Accepted
time: 151ms
memory: 29812kb
Test #8:
score: 0
Accepted
time: 156ms
memory: 29952kb
Test #9:
score: 0
Accepted
time: 1ms
memory: 3608kb
Test #10:
score: 0
Accepted
time: 1ms
memory: 3636kb
Test #11:
score: 0
Accepted
time: 1ms
memory: 3660kb
Test #12:
score: 0
Accepted
time: 1ms
memory: 3632kb
Test #13:
score: 0
Accepted
time: 0ms
memory: 3688kb
Test #14:
score: 0
Accepted
time: 0ms
memory: 3660kb
Test #15:
score: 0
Accepted
time: 0ms
memory: 3632kb
Test #16:
score: 0
Accepted
time: 223ms
memory: 21224kb
Test #17:
score: 0
Accepted
time: 366ms
memory: 23288kb
Test #18:
score: 0
Accepted
time: 597ms
memory: 36120kb
Test #19:
score: 0
Accepted
time: 0ms
memory: 3600kb
Test #20:
score: 0
Accepted
time: 561ms
memory: 38592kb
Test #21:
score: 0
Accepted
time: 331ms
memory: 32408kb
Test #22:
score: 0
Accepted
time: 247ms
memory: 28124kb
Test #23:
score: 0
Accepted
time: 18ms
memory: 8604kb
Test #24:
score: 0
Accepted
time: 589ms
memory: 40740kb
Test #25:
score: 0
Accepted
time: 522ms
memory: 44272kb
Test #26:
score: 0
Accepted
time: 305ms
memory: 29400kb
Test #27:
score: 0
Accepted
time: 127ms
memory: 21864kb
Test #28:
score: 0
Accepted
time: 478ms
memory: 37280kb
Test #29:
score: 0
Accepted
time: 2ms
memory: 6100kb
Test #30:
score: 0
Accepted
time: 0ms
memory: 3664kb
Test #31:
score: 0
Accepted
time: 3ms
memory: 6176kb
Test #32:
score: 0
Accepted
time: 6ms
memory: 9272kb
Test #33:
score: 0
Accepted
time: 1ms
memory: 3664kb
Test #34:
score: 0
Accepted
time: 1ms
memory: 3664kb
Test #35:
score: 0
Accepted
time: 0ms
memory: 3624kb
Test #36:
score: 0
Accepted
time: 1ms
memory: 3620kb
Test #37:
score: 0
Accepted
time: 1ms
memory: 3600kb
Test #38:
score: 0
Accepted
time: 0ms
memory: 3656kb
Test #39:
score: 0
Accepted
time: 0ms
memory: 3612kb
Test #40:
score: 0
Accepted
time: 0ms
memory: 3636kb
Test #41:
score: 0
Accepted
time: 9ms
memory: 5128kb
Test #42:
score: 0
Accepted
time: 6ms
memory: 5228kb
Test #43:
score: 0
Accepted
time: 3ms
memory: 5144kb
Test #44:
score: 0
Accepted
time: 9ms
memory: 5128kb
Test #45:
score: 0
Accepted
time: 6ms
memory: 5076kb
Test #46:
score: 0
Accepted
time: 9ms
memory: 5144kb
Test #47:
score: 0
Accepted
time: 98ms
memory: 12104kb
Test #48:
score: 0
Accepted
time: 99ms
memory: 12360kb
Test #49:
score: 0
Accepted
time: 104ms
memory: 12528kb
Test #50:
score: 0
Accepted
time: 69ms
memory: 10032kb
Test #51:
score: 0
Accepted
time: 66ms
memory: 10172kb
Test #52:
score: 0
Accepted
time: 67ms
memory: 9980kb
Test #53:
score: 0
Accepted
time: 206ms
memory: 17808kb
Test #54:
score: 0
Accepted
time: 203ms
memory: 17616kb
Test #55:
score: 0
Accepted
time: 191ms
memory: 17832kb
Test #56:
score: 0
Accepted
time: 178ms
memory: 16488kb
Test #57:
score: 0
Accepted
time: 177ms
memory: 16508kb
Test #58:
score: 0
Accepted
time: 171ms
memory: 16512kb
Test #59:
score: 0
Accepted
time: 0ms
memory: 3668kb
Test #60:
score: 0
Accepted
time: 0ms
memory: 7172kb
Test #61:
score: 0
Accepted
time: 0ms
memory: 4716kb
Test #62:
score: 0
Accepted
time: 1ms
memory: 3620kb