QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#368991 | #2428. Comma Sprinkler | InfinityNS# | AC ✓ | 698ms | 129696kb | C++14 | 2.9kb | 2024-03-27 18:58:28 | 2024-03-27 18:58:29 |
Judging History
answer
#include<bits/stdc++.h>
#define f first
#define s second
#define ld long double
#define pb push_back
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;
int main(){
int n;
vector<string> words;
vector<bool> hasComma,hasDot;
string in;
set<pair<string,int>> before,after;
while(cin>>in){
if(sz(in)==0)break;
if(in[sz(in)-1]==','){
in=in.substr(0, sz(in)-1);
hasComma.pb(1);
}
else{
hasComma.pb(0);
}
if(in[sz(in)-1]=='.'){
in=in.substr(0, sz(in)-1);
hasDot.pb(1);
}
else{
hasDot.pb(0);
}
words.pb(in);
}
queue<string> qb,qa;
for(int i=0;i<sz(words);i++){
if(i!=0){
if(!hasComma[i-1]&&!hasDot[i-1]){
before.insert({words[i],i-1});
}
if(hasComma[i-1]){
qb.push(words[i]);
}
}
if(!hasComma[i]&&!hasDot[i]){
after.insert({words[i],i});
}
if(hasComma[i]){
qa.push(words[i]);
}
}
while(sz(qb)||sz(qa)){
while(sz(qb)){
string tr=qb.front();
//cout << "before " << tr << endl;
qb.pop();
while(1){
//cout << tr << endl;
auto it=before.lower_bound({tr,0});
if(it!=before.end()&&(*it).f==tr){
//cout << sz(before) << endl;
int pos=(*it).s;
if(!hasComma[pos]){
hasComma[pos]=1;
qa.push(words[pos]);
if(pos!=sz(hasComma)-1){
qb.push(words[pos+1]);
}
}
before.erase(it);
}
else{
break;
}
}
}
while(sz(qa)){
string tr=qa.front();
//cout << "after " << tr << endl;
qa.pop();
while(1){
auto it=after.lower_bound({tr,0});
if(it!=after.end()&&(*it).f==tr){
int pos=(*it).s;
if(!hasComma[pos]){
hasComma[pos]=1;
qa.push(words[pos]);
if(pos!=sz(hasComma)-1){
qb.push(words[pos+1]);
}
}
after.erase(it);
}
else{
break;
}
}
}
}
//cout << "done" << endl;
for(int i=0;i<sz(words);i++){
cout << words[i];
if(hasComma[i])cout << ",";
if(hasDot[i])cout << ".";
cout << " ";
}
cout << endl;
}
Details
Test #1:
score: 100
Accepted
time: 1ms
memory: 3612kb
Test #2:
score: 0
Accepted
time: 1ms
memory: 3600kb
Test #3:
score: 0
Accepted
time: 0ms
memory: 3612kb
Test #4:
score: 0
Accepted
time: 1ms
memory: 3788kb
Test #5:
score: 0
Accepted
time: 1ms
memory: 3584kb
Test #6:
score: 0
Accepted
time: 463ms
memory: 129696kb
Test #7:
score: 0
Accepted
time: 230ms
memory: 40780kb
Test #8:
score: 0
Accepted
time: 220ms
memory: 40732kb
Test #9:
score: 0
Accepted
time: 1ms
memory: 3604kb
Test #10:
score: 0
Accepted
time: 1ms
memory: 3544kb
Test #11:
score: 0
Accepted
time: 1ms
memory: 3520kb
Test #12:
score: 0
Accepted
time: 0ms
memory: 3596kb
Test #13:
score: 0
Accepted
time: 1ms
memory: 3620kb
Test #14:
score: 0
Accepted
time: 1ms
memory: 3556kb
Test #15:
score: 0
Accepted
time: 1ms
memory: 3620kb
Test #16:
score: 0
Accepted
time: 650ms
memory: 102764kb
Test #17:
score: 0
Accepted
time: 673ms
memory: 78612kb
Test #18:
score: 0
Accepted
time: 698ms
memory: 64216kb
Test #19:
score: 0
Accepted
time: 1ms
memory: 3532kb
Test #20:
score: 0
Accepted
time: 593ms
memory: 55696kb
Test #21:
score: 0
Accepted
time: 355ms
memory: 40032kb
Test #22:
score: 0
Accepted
time: 247ms
memory: 33776kb
Test #23:
score: 0
Accepted
time: 22ms
memory: 10512kb
Test #24:
score: 0
Accepted
time: 303ms
memory: 35520kb
Test #25:
score: 0
Accepted
time: 52ms
memory: 22528kb
Test #26:
score: 0
Accepted
time: 237ms
memory: 30268kb
Test #27:
score: 0
Accepted
time: 39ms
memory: 11540kb
Test #28:
score: 0
Accepted
time: 199ms
memory: 26216kb
Test #29:
score: 0
Accepted
time: 3ms
memory: 6356kb
Test #30:
score: 0
Accepted
time: 0ms
memory: 3588kb
Test #31:
score: 0
Accepted
time: 6ms
memory: 4832kb
Test #32:
score: 0
Accepted
time: 13ms
memory: 6476kb
Test #33:
score: 0
Accepted
time: 1ms
memory: 3584kb
Test #34:
score: 0
Accepted
time: 1ms
memory: 3704kb
Test #35:
score: 0
Accepted
time: 1ms
memory: 3528kb
Test #36:
score: 0
Accepted
time: 1ms
memory: 3836kb
Test #37:
score: 0
Accepted
time: 0ms
memory: 3496kb
Test #38:
score: 0
Accepted
time: 0ms
memory: 3568kb
Test #39:
score: 0
Accepted
time: 0ms
memory: 3532kb
Test #40:
score: 0
Accepted
time: 0ms
memory: 3492kb
Test #41:
score: 0
Accepted
time: 15ms
memory: 6620kb
Test #42:
score: 0
Accepted
time: 15ms
memory: 6540kb
Test #43:
score: 0
Accepted
time: 11ms
memory: 6472kb
Test #44:
score: 0
Accepted
time: 11ms
memory: 6536kb
Test #45:
score: 0
Accepted
time: 14ms
memory: 6592kb
Test #46:
score: 0
Accepted
time: 15ms
memory: 6544kb
Test #47:
score: 0
Accepted
time: 181ms
memory: 26640kb
Test #48:
score: 0
Accepted
time: 171ms
memory: 26492kb
Test #49:
score: 0
Accepted
time: 175ms
memory: 26760kb
Test #50:
score: 0
Accepted
time: 82ms
memory: 15232kb
Test #51:
score: 0
Accepted
time: 82ms
memory: 15188kb
Test #52:
score: 0
Accepted
time: 88ms
memory: 15208kb
Test #53:
score: 0
Accepted
time: 413ms
memory: 52040kb
Test #54:
score: 0
Accepted
time: 369ms
memory: 51860kb
Test #55:
score: 0
Accepted
time: 394ms
memory: 52136kb
Test #56:
score: 0
Accepted
time: 321ms
memory: 41044kb
Test #57:
score: 0
Accepted
time: 318ms
memory: 40816kb
Test #58:
score: 0
Accepted
time: 302ms
memory: 40676kb
Test #59:
score: 0
Accepted
time: 1ms
memory: 3824kb
Test #60:
score: 0
Accepted
time: 8ms
memory: 5236kb
Test #61:
score: 0
Accepted
time: 14ms
memory: 6676kb
Test #62:
score: 0
Accepted
time: 0ms
memory: 3544kb