QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#372034#2428. Comma SprinklerUFRJ#AC ✓207ms34636kbC++201.5kb2024-03-30 19:50:322024-03-30 19:50:32

Judging History

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

  • [2024-03-30 19:50:32]
  • 评测
  • 测评结果:AC
  • 用时:207ms
  • 内存:34636kb
  • [2024-03-30 19:50:32]
  • 提交

answer

#include "bits/stdc++.h"

using namespace std;
using lint = int64_t;

int main(void) {
    cin.tie(nullptr)->sync_with_stdio(false);
    vector<string>t;
    string s;
    while(cin>>s) t.push_back(s);
    int n = (int)t.size();
    vector<bool>dot(n);
    map<string, int>id;
    vector<int>line_id(n);
    vector<int>v;
    for(int i=0;i<n;i++){
        bool ok = false;
        if(t[i].back() == '.'){
            dot[i] = 1;
            t[i].pop_back();
        }
        else if(t[i].back() == ','){
            ok = true;
            t[i].pop_back();
        }
        if(!id.count(t[i])){
            id[t[i]] = id.size();
        }
        line_id[i] = id[t[i]];
        if(ok) v.push_back(line_id[i]);
    }
    int m = (int)id.size();
    vector<vector<int>>g(m+m);
    vector<bool>vis(m+m);
    for(int i=1;i<n;i++){
        if(dot[i-1]) continue;
        int j = line_id[i-1], k = line_id[i];
        g[j].push_back(k+m);
        g[k+m].push_back(j);
    }
    auto dfs = [&](auto& self, int u)->void {
        vis[u] = 1;
        for(int v : g[u]){
            if(vis[v]) continue;
            self(self, v);
        }
    };
    for(int i : v){
        if(!vis[i]) dfs(dfs, i);
    }
    for(int i=0;i<n;i++){
        if(dot[i]){
            t[i] += '.';
            continue;
        }
        if(vis[line_id[i]]){
            t[i] += ',';
        }        
    }
    cout<<t[0];
    for(int i=1;i<n;i++) cout<<" "<<t[i];
    cout<<"\n";


    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3772kb

Test #2:

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

Test #3:

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

Test #4:

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

Test #5:

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

Test #6:

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

Test #7:

score: 0
Accepted
time: 101ms
memory: 31456kb

Test #8:

score: 0
Accepted
time: 101ms
memory: 31508kb

Test #9:

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

Test #10:

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

Test #11:

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

Test #12:

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

Test #13:

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

Test #14:

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

Test #15:

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

Test #16:

score: 0
Accepted
time: 93ms
memory: 21876kb

Test #17:

score: 0
Accepted
time: 114ms
memory: 22264kb

Test #18:

score: 0
Accepted
time: 207ms
memory: 30840kb

Test #19:

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

Test #20:

score: 0
Accepted
time: 204ms
memory: 34636kb

Test #21:

score: 0
Accepted
time: 172ms
memory: 33832kb

Test #22:

score: 0
Accepted
time: 163ms
memory: 31260kb

Test #23:

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

Test #24:

score: 0
Accepted
time: 175ms
memory: 31520kb

Test #25:

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

Test #26:

score: 0
Accepted
time: 165ms
memory: 27988kb

Test #27:

score: 0
Accepted
time: 133ms
memory: 22024kb

Test #28:

score: 0
Accepted
time: 168ms
memory: 29248kb

Test #29:

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

Test #30:

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

Test #31:

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

Test #32:

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

Test #33:

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

Test #34:

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

Test #35:

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

Test #36:

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

Test #37:

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

Test #38:

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

Test #39:

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

Test #40:

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

Test #41:

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

Test #42:

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

Test #43:

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

Test #44:

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

Test #45:

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

Test #46:

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

Test #47:

score: 0
Accepted
time: 41ms
memory: 12152kb

Test #48:

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

Test #49:

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

Test #50:

score: 0
Accepted
time: 32ms
memory: 9664kb

Test #51:

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

Test #52:

score: 0
Accepted
time: 28ms
memory: 9560kb

Test #53:

score: 0
Accepted
time: 87ms
memory: 17988kb

Test #54:

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

Test #55:

score: 0
Accepted
time: 99ms
memory: 18168kb

Test #56:

score: 0
Accepted
time: 82ms
memory: 16444kb

Test #57:

score: 0
Accepted
time: 84ms
memory: 16444kb

Test #58:

score: 0
Accepted
time: 78ms
memory: 16572kb

Test #59:

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

Test #60:

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

Test #61:

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

Test #62:

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