QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#639915#2428. Comma SprinklerTrentiumWA 180ms120812kbC++143.3kb2024-10-13 23:52:152024-10-13 23:52:16

Judging History

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

  • [2024-10-13 23:52:16]
  • 评测
  • 测评结果:WA
  • 用时:180ms
  • 内存:120812kb
  • [2024-10-13 23:52:15]
  • 提交

answer

#include "bits/extc++.h"

using namespace std;
using namespace __gnu_pbds;
#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 gp_hash_table<ll, vector<ll>> string_map;
typedef gp_hash_table<ll, bool> string_set;
typedef pair<ll, bool> node;

const ll B = 831, M = 38278592781;

ll hasher(const string& x) {
    ll cur = 15;
    for(char i : x) cur = (cur * B + i) % M;
    return cur;
}

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);

    string_map ads;
    string_map adp;
    string_set viss;
    string_set visp;
    vector<node> bfs;

    forR(i, (int) nocom.size() - 1) if(nocom[i] != "." && nocom[i+1] != ".") {
        ads[hasher(nocom[i])].push_back(hasher(nocom[i+1]));
        adp[hasher(nocom[i+1])].push_back(hasher(nocom[i]));
    }
    forR(i, (int) tokens.size() - 1) if(tokens[i] != "." && tokens[i] != ",") {
        if(i > 0 && tokens[i-1] == ",") {
            visp[hasher(tokens[i])] = true;
            bfs.push_back({hasher(tokens[i]), false});
        }
        if(i + 1 < tokens.size() && tokens[i+1] == ",") {
            bfs.push_back({hasher(tokens[i]), true});
            viss[hasher(tokens[i])] = true;
        }
    }
    int tot = 0;
    while(!bfs.empty()){
        node cur = bfs.back();
        bfs.pop_back();
        ++tot;
        assert(tot < 2 * tokens.size() + 10);
        if(cur.second) {
            for(ll nex : ads[cur.first]) if(!visp[nex]) {
                bfs.push_back({nex, false});
                visp[nex] = true;
            }
        } else {
            for(ll nex : adp[cur.first]) if(!viss[nex]) {
                bfs.push_back({nex, true});
                viss[nex] = true;
            }
        }
    }

    vector<string> toPrint;
    forR(ci, nocom.size()) {
        string i = nocom[ci];
        if(i == ".") toPrint.push_back(". ");
        else {
            if(visp[hasher(i)] && !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: 3580kb

Test #2:

score: 0
Accepted
time: 0ms
memory: 3640kb

Test #3:

score: 0
Accepted
time: 0ms
memory: 3612kb

Test #4:

score: 0
Accepted
time: 0ms
memory: 3884kb

Test #5:

score: 0
Accepted
time: 0ms
memory: 3608kb

Test #6:

score: 0
Accepted
time: 62ms
memory: 94304kb

Test #7:

score: 0
Accepted
time: 98ms
memory: 83108kb

Test #8:

score: 0
Accepted
time: 110ms
memory: 82240kb

Test #9:

score: 0
Accepted
time: 0ms
memory: 3888kb

Test #10:

score: 0
Accepted
time: 0ms
memory: 3604kb

Test #11:

score: 0
Accepted
time: 1ms
memory: 3728kb

Test #12:

score: 0
Accepted
time: 0ms
memory: 3584kb

Test #13:

score: 0
Accepted
time: 1ms
memory: 4024kb

Test #14:

score: 0
Accepted
time: 1ms
memory: 3720kb

Test #15:

score: 0
Accepted
time: 0ms
memory: 3668kb

Test #16:

score: 0
Accepted
time: 164ms
memory: 93184kb

Test #17:

score: 0
Accepted
time: 141ms
memory: 92160kb

Test #18:

score: 0
Accepted
time: 180ms
memory: 120812kb

Test #19:

score: 0
Accepted
time: 0ms
memory: 3616kb

Test #20:

score: 0
Accepted
time: 157ms
memory: 88536kb

Test #21:

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

Test #22:

score: -100
Wrong Answer
time: 124ms
memory: 81172kb