QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#56045#2428. Comma Sprinklercaptured#WA 224ms47808kbC++4.0kb2022-10-16 17:40:072022-10-16 17:40:09

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-16 17:40:09]
  • 评测
  • 测评结果:WA
  • 用时:224ms
  • 内存:47808kb
  • [2022-10-16 17:40:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define read()          freopen("consistency_chapter_1_input.txt","r",stdin)
#define write()         freopen("out.txt","w",stdout)
#define sf(n)           scanf("%d",&n)
#define sfd(n)          scanf("%lf",&n)
#define sl(x)           scanf("%I64d",&x)
#define sfl(n)          scanf("%lld", &n)
#define sfc(n)          scanf(" %c",&n)
#define sful(n)         scanf("%llu",&n)
#define ull             unsigned long long
#define endll           pf("\n")
#define pf              printf
#define PI              acos(-1.0)
#define eps             1e-12
#define mem(a,b)        memset(a,b,sizeof(a))
#define pb              push_back
#define xx              first
#define yy              second
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define MP make_pair
#define ll              long long
#define uniq(a)      a.erase(unique(a.begin(), a.end()), a.end())
#define cnd tree[idx]
#define lnd tree[idx<<1]
#define rnd tree[(idx<<1)+1]
#define lndp (idx<<1),(b),((b+e)>>1)
#define rndp ((idx<<1)+1),(((b+e)>>1)+1),(e)
#define inf 1999999999
#define MOD  1000000007
#define mod1 1000000009
#define var    int n,m,i,j,c=0,t,l,r,mid,z=0,k,x,y
#define aloc(n,t) ((t*)malloc((n)*sizeof(t)))

int dx[8]={0,0,1,1,-1,-1,1,-1};  //8 direction
int dy[8]={1,-1,1,-1,1,-1,0,0};
//int dx[4]={1,-1,0,0};  //4 direction
//int dy[4]={0,0,1,-1};

//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//
//using namespace std;
//using namespace __gnu_pbds;
//
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//
//ordered_set<int> os;
const ll mod = 998244353;
const int N = 2e6 + 5;
string s, a, b;
map<string, vector<int>> mp, mp2;
vector<int> p;
vector<string> w, v;
queue<int> q;
int vis[N];
int main() {
    ll n, t, k;
    getline(cin, s);
    n = s.size();
    for (int i = 0; i < n; i++) {
        if (s[i] == ' ') {
            if (a.size() > 0) {
                b = a;
                k = a.size();
                if (a[k-1] == ',' || a[k-1] == '.') {
                    a.erase(k-1, 1);
                }
                mp[a].pb(w.size());
                mp2[b].pb(w.size());
                k = a.size();
                w.pb(b);
                v.pb(a);
                a = "";
            }
            continue;
        }
        a += s[i];
    }
    if (a.size()) {
        b = a;
        k = a.size();
        if (a[k-1] == ',' || a[k-1] == '.') {
            a.erase(k-1, 1);
        }
        mp[a].pb(w.size());
        mp2[b].pb(w.size());
        w.pb(b);
        v.pb(a);
    }
//    cout<<"K"<<endl;
    int sz = v.size();
    for (int i = 0; i < sz; i++) {
        k = w[i].size();
        if (w[i][k-1] == ',') {
            q.push(i);
            vis[i] = 1;
        }
    }
    while (q.empty() == 0) {
        int x = q.front();
        q.pop();
        a = v[x];
        p = mp2[a];
        for (auto y: p) {
            if (vis[y]==0) {
                vis[y] = 1;
                t = w[y].size();
                if (w[y][t-1] == '.' || w[y][t-1] == ',') continue;
                w[y] += ',';
                q.push(y);
            }
        }
        mp2[a].clear();
        if (x+1 < sz && vis[x+1] == 0) {
            a = v[x + 1];
            p = mp[a];
            for(auto y: p) {
                if (y - 1 >= 0 && vis[y-1] == 0) {
                    t = w[y-1].size();
                    vis[y-1] = 1;
                    if (w[y-1][t-1] == '.' || w[y-1][t-1] == ',') continue;
                    w[y-1] += ',';
                    q.push(y-1);
                }
            }
            mp[a].clear();
        }
    }

    s = "";
    for (auto x : w) {
        if (s.size() > 0) s += ' ';
        s += x;
    }
    cout<<s<<endl;

}


详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 3732kb

Test #2:

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

Test #3:

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

Test #4:

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

Test #5:

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

Test #6:

score: 0
Accepted
time: 83ms
memory: 47808kb

Test #7:

score: 0
Accepted
time: 189ms
memory: 42700kb

Test #8:

score: 0
Accepted
time: 224ms
memory: 42708kb

Test #9:

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

Test #10:

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

Test #11:

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

Test #12:

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

Test #13:

score: -100
Wrong Answer
time: 0ms
memory: 3720kb