QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#380752#2428. Comma Sprinkler8BQube#AC ✓77ms34156kbC++202.1kb2024-04-07 11:18:122024-04-07 11:18:12

Judging History

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

  • [2024-04-07 11:18:12]
  • 评测
  • 测评结果:AC
  • 用时:77ms
  • 内存:34156kb
  • [2024-04-07 11:18:12]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define SZ(a) ((int)a.size())

unordered_map<string, int> smp;
vector<string> ismp;
int get(const string &s) {
    auto it = smp.find(s);
    if (it != smp.end())
        return it->Y;
    int t = SZ(smp);
    smp[s] = t;
    ismp.pb(s);
    return t;
}

struct S {
    int idx;
    int com, per;
};

const int N = 1e6 + 6;
int pre[N], aft[N];
#define prev aaa
vector<int> prev[N], aftv[N];



int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    vector<S> v;
    string s;
    while (cin >> s) {
        S p = {0, 0, 0};
        if (s.back() == ',')
            p.com = 1, s.pop_back(); 
        else if (s.back() == '.')
            p.per = 1, s.pop_back();
        p.idx = get(s);
        v.pb(p);
    }
    queue<pii> q;
    auto mkpre = [&](int x) {
        if (pre[x]) return;
        pre[x] = 1;
        q.push({x, 0});
    };
    auto mkaft = [&](int x) {
        if (aft[x]) return;
        aft[x] = 1;
        q.push({x, 1});
    };
    for (int i = 0; i < SZ(v); i++) {
        if (i != 0 && !v[i - 1].per) {
            prev[v[i].idx].pb(v[i - 1].idx);
            if (v[i - 1].com)
                mkpre(v[i].idx);
        }
        if (i != SZ(v) - 1 && !v[i].per) {
            aftv[v[i].idx].pb(v[i + 1].idx);
            if (v[i].com)
                mkaft(v[i].idx);
        }
    }
    while (SZ(q)) {
        auto p = q.front(); q.pop();
        if (p.Y == 0) {
            // pre
            for (int t : prev[p.X])
                mkaft(t);
        }
        else {
            // aft 
            for (int t : aftv[p.X])
                mkpre(t);
        }
    }
    for (int i = 0; i < SZ(v); i++) {
        if (!v[i].per) {
            if (aft[v[i].idx] || (i + 1 < SZ(v) && pre[v[i + 1].idx]))
                v[i].com = 1;
        }
        cout << ismp[v[i].idx];
        if (v[i].com)
            cout << ",";
        else if (v[i].per)
            cout << ".";
        cout << " \n"[i + 1 == SZ(v)];
    }
}

详细

Test #1:

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

Test #2:

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

Test #3:

score: 0
Accepted
time: 2ms
memory: 3636kb

Test #4:

score: 0
Accepted
time: 2ms
memory: 3520kb

Test #5:

score: 0
Accepted
time: 2ms
memory: 3648kb

Test #6:

score: 0
Accepted
time: 37ms
memory: 14412kb

Test #7:

score: 0
Accepted
time: 53ms
memory: 27828kb

Test #8:

score: 0
Accepted
time: 44ms
memory: 28328kb

Test #9:

score: 0
Accepted
time: 2ms
memory: 3812kb

Test #10:

score: 0
Accepted
time: 2ms
memory: 3596kb

Test #11:

score: 0
Accepted
time: 2ms
memory: 3692kb

Test #12:

score: 0
Accepted
time: 2ms
memory: 3632kb

Test #13:

score: 0
Accepted
time: 2ms
memory: 3568kb

Test #14:

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

Test #15:

score: 0
Accepted
time: 2ms
memory: 3892kb

Test #16:

score: 0
Accepted
time: 35ms
memory: 13592kb

Test #17:

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

Test #18:

score: 0
Accepted
time: 75ms
memory: 29052kb

Test #19:

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

Test #20:

score: 0
Accepted
time: 77ms
memory: 33660kb

Test #21:

score: 0
Accepted
time: 58ms
memory: 34156kb

Test #22:

score: 0
Accepted
time: 54ms
memory: 32132kb

Test #23:

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

Test #24:

score: 0
Accepted
time: 74ms
memory: 31008kb

Test #25:

score: 0
Accepted
time: 75ms
memory: 30196kb

Test #26:

score: 0
Accepted
time: 63ms
memory: 27692kb

Test #27:

score: 0
Accepted
time: 42ms
memory: 18144kb

Test #28:

score: 0
Accepted
time: 70ms
memory: 28680kb

Test #29:

score: 0
Accepted
time: 5ms
memory: 5896kb

Test #30:

score: 0
Accepted
time: 2ms
memory: 3592kb

Test #31:

score: 0
Accepted
time: 2ms
memory: 5628kb

Test #32:

score: 0
Accepted
time: 5ms
memory: 5660kb

Test #33:

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

Test #34:

score: 0
Accepted
time: 2ms
memory: 3900kb

Test #35:

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

Test #36:

score: 0
Accepted
time: 2ms
memory: 3880kb

Test #37:

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

Test #38:

score: 0
Accepted
time: 2ms
memory: 3644kb

Test #39:

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

Test #40:

score: 0
Accepted
time: 2ms
memory: 3580kb

Test #41:

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

Test #42:

score: 0
Accepted
time: 3ms
memory: 5288kb

Test #43:

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

Test #44:

score: 0
Accepted
time: 5ms
memory: 5528kb

Test #45:

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

Test #46:

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

Test #47:

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

Test #48:

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

Test #49:

score: 0
Accepted
time: 17ms
memory: 9488kb

Test #50:

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

Test #51:

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

Test #52:

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

Test #53:

score: 0
Accepted
time: 44ms
memory: 12396kb

Test #54:

score: 0
Accepted
time: 38ms
memory: 12524kb

Test #55:

score: 0
Accepted
time: 40ms
memory: 12492kb

Test #56:

score: 0
Accepted
time: 36ms
memory: 11360kb

Test #57:

score: 0
Accepted
time: 35ms
memory: 11336kb

Test #58:

score: 0
Accepted
time: 36ms
memory: 12076kb

Test #59:

score: 0
Accepted
time: 2ms
memory: 3632kb

Test #60:

score: 0
Accepted
time: 5ms
memory: 6276kb

Test #61:

score: 0
Accepted
time: 2ms
memory: 3564kb

Test #62:

score: 0
Accepted
time: 2ms
memory: 3580kb