QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#372063#2428. Comma SprinklerWe_Are_Chenough#AC ✓411ms111072kbC++142.5kb2024-03-30 20:42:242024-03-30 20:42:24

Judging History

你现在查看的是最新测评结果

  • [2024-03-30 20:42:24]
  • 评测
  • 测评结果:AC
  • 用时:411ms
  • 内存:111072kb
  • [2024-03-30 20:42:24]
  • 提交

answer

#include "bits/stdc++.h"

using namespace std;

#define endl '\n'

typedef long long ll;

const int mxn = 1e6+5;

map<string, int> mapa;

string rmapa[mxn];

int memo[mxn][2];

vector<int> bf[mxn], af[mxn];

queue<int> pre, suf;

void bfs(){
    while(!pre.empty() || !suf.empty()){
        if(!pre.empty()){
            int agr = pre.front();
            pre.pop();
            if(memo[agr][0]) continue;

            memo[agr][0]=1;

            for(int i:bf[agr]){
                suf.push(i);
            }
        }

        if(!suf.empty()){
            int agr = suf.front();
            suf.pop();

            if(memo[agr][1]) continue;

            memo[agr][1]=1;

            for(int i:af[agr]){
                pre.push(i);
            }

        }
    }

}

signed main(){
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    string ss;

    getline(cin, ss);

    int n = int(ss.size());

    int cont = 0, vir = 0;
    string wrd = "";

    vector<pair<string, int> > only_wrd;

    for(int i=0; i<n; i++){
        if(ss[i]==' ' || ss[i]=='.'){
            if(wrd.empty()) continue;
            if(!mapa.count(wrd)){
                mapa[wrd]=++cont;
                rmapa[cont]=wrd;
            }
            if(ss[i]=='.') vir = 2;
            only_wrd.push_back({wrd, vir});
            wrd = "";
            vir = 0;
        }else if(ss[i]==','){
            vir = 1;
        }
        else{
            wrd+=ss[i];
        }
    }
    for(int i=0; i<int(only_wrd.size())-1; i++){
        auto agr = only_wrd[i];
        auto nxt = only_wrd[i+1];

        int c1 = mapa[agr.first];
        int c2 = mapa[nxt.first];

        if(agr.second!=2){
            af[c1].push_back(c2);
            bf[c2].push_back(c1);   
        }

        if(agr.second==1){
            pre.push(mapa[nxt.first]);
            suf.push(mapa[agr.first]);
        }
    }
    bfs();

    wrd = "";
    vir = 0;

    for(int i=0; i<n; i++){
        if(ss[i]=='.'){
            cout << wrd << ". ";
            wrd = "";
            vir = 0;
        }else if(ss[i]==' '){
            if(wrd.empty()) continue;
            
            int agr = mapa[wrd];

            if((!vir && memo[agr][1]) || vir){
                cout << wrd << ", ";
            }else{
                cout << wrd << " ";
            }

            wrd = "";
            vir = 0;
        }else if(ss[i]==','){
            vir = 1;
        }else{
            wrd+=ss[i];
        }
    }

    return 0;
}

Details

Test #1:

score: 100
Accepted
time: 8ms
memory: 81728kb

Test #2:

score: 0
Accepted
time: 12ms
memory: 81720kb

Test #3:

score: 0
Accepted
time: 15ms
memory: 81736kb

Test #4:

score: 0
Accepted
time: 7ms
memory: 81760kb

Test #5:

score: 0
Accepted
time: 11ms
memory: 81728kb

Test #6:

score: 0
Accepted
time: 59ms
memory: 109892kb

Test #7:

score: 0
Accepted
time: 139ms
memory: 105108kb

Test #8:

score: 0
Accepted
time: 151ms
memory: 104944kb

Test #9:

score: 0
Accepted
time: 21ms
memory: 81736kb

Test #10:

score: 0
Accepted
time: 21ms
memory: 81788kb

Test #11:

score: 0
Accepted
time: 8ms
memory: 81752kb

Test #12:

score: 0
Accepted
time: 11ms
memory: 81764kb

Test #13:

score: 0
Accepted
time: 11ms
memory: 81956kb

Test #14:

score: 0
Accepted
time: 15ms
memory: 81792kb

Test #15:

score: 0
Accepted
time: 15ms
memory: 81696kb

Test #16:

score: 0
Accepted
time: 149ms
memory: 105084kb

Test #17:

score: 0
Accepted
time: 260ms
memory: 104012kb

Test #18:

score: 0
Accepted
time: 388ms
memory: 108892kb

Test #19:

score: 0
Accepted
time: 8ms
memory: 81680kb

Test #20:

score: 0
Accepted
time: 411ms
memory: 111072kb

Test #21:

score: 0
Accepted
time: 317ms
memory: 108936kb

Test #22:

score: 0
Accepted
time: 311ms
memory: 106424kb

Test #23:

score: 0
Accepted
time: 47ms
memory: 89640kb

Test #24:

score: 0
Accepted
time: 410ms
memory: 108536kb

Test #25:

score: 0
Accepted
time: 374ms
memory: 107492kb

Test #26:

score: 0
Accepted
time: 296ms
memory: 104360kb

Test #27:

score: 0
Accepted
time: 206ms
memory: 98008kb

Test #28:

score: 0
Accepted
time: 344ms
memory: 105984kb

Test #29:

score: 0
Accepted
time: 11ms
memory: 85180kb

Test #30:

score: 0
Accepted
time: 8ms
memory: 81684kb

Test #31:

score: 0
Accepted
time: 8ms
memory: 84840kb

Test #32:

score: 0
Accepted
time: 19ms
memory: 85256kb

Test #33:

score: 0
Accepted
time: 7ms
memory: 81984kb

Test #34:

score: 0
Accepted
time: 8ms
memory: 81736kb

Test #35:

score: 0
Accepted
time: 8ms
memory: 81736kb

Test #36:

score: 0
Accepted
time: 11ms
memory: 81736kb

Test #37:

score: 0
Accepted
time: 7ms
memory: 81692kb

Test #38:

score: 0
Accepted
time: 7ms
memory: 81784kb

Test #39:

score: 0
Accepted
time: 15ms
memory: 81732kb

Test #40:

score: 0
Accepted
time: 8ms
memory: 81776kb

Test #41:

score: 0
Accepted
time: 16ms
memory: 83600kb

Test #42:

score: 0
Accepted
time: 22ms
memory: 83408kb

Test #43:

score: 0
Accepted
time: 27ms
memory: 83464kb

Test #44:

score: 0
Accepted
time: 25ms
memory: 83424kb

Test #45:

score: 0
Accepted
time: 24ms
memory: 83520kb

Test #46:

score: 0
Accepted
time: 20ms
memory: 83516kb

Test #47:

score: 0
Accepted
time: 97ms
memory: 90004kb

Test #48:

score: 0
Accepted
time: 95ms
memory: 90188kb

Test #49:

score: 0
Accepted
time: 94ms
memory: 90196kb

Test #50:

score: 0
Accepted
time: 68ms
memory: 87924kb

Test #51:

score: 0
Accepted
time: 76ms
memory: 87920kb

Test #52:

score: 0
Accepted
time: 69ms
memory: 87992kb

Test #53:

score: 0
Accepted
time: 173ms
memory: 97388kb

Test #54:

score: 0
Accepted
time: 174ms
memory: 97364kb

Test #55:

score: 0
Accepted
time: 171ms
memory: 97428kb

Test #56:

score: 0
Accepted
time: 170ms
memory: 95196kb

Test #57:

score: 0
Accepted
time: 166ms
memory: 95204kb

Test #58:

score: 0
Accepted
time: 161ms
memory: 95204kb

Test #59:

score: 0
Accepted
time: 8ms
memory: 81732kb

Test #60:

score: 0
Accepted
time: 16ms
memory: 86476kb

Test #61:

score: 0
Accepted
time: 19ms
memory: 83360kb

Test #62:

score: 0
Accepted
time: 8ms
memory: 81912kb