QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#372061#2428. Comma SprinklerWe_Are_Chenough#WA 4ms81776kbC++142.7kb2024-03-30 20:41:532024-03-30 20:41:54

Judging History

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

  • [2024-03-30 20:41:54]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:81776kb
  • [2024-03-30 20:41:53]
  • 提交

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=1; i<=cont; i++){
        cout << rmapa[i] << ' ' << memo[i][0] << ' ' << memo[i][1] << endl;
    }

    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: 0
Wrong Answer
time: 4ms
memory: 81776kb