QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#56038#2428. Comma Sprinklercaptured#WA 222ms47616kbC++4.2kb2022-10-16 17:09:522022-10-16 17:09:54

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:09:54]
  • 评测
  • 测评结果:WA
  • 用时:222ms
  • 内存:47616kb
  • [2022-10-16 17:09:52]
  • 提交

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();
                while(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();
            while(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();
//            cout<<x<<endl;
        a = v[x]; k = a.size();
        if (w[x][k-1] == '.') continue;
        if (a[k-1] == ',') {
            a.erase(k-1, 1);
        }
//    cout<<a<<endl;
        t = w[x].size();
        if (w[x][t-1] != ',' && w[x][t-1] != '.') {
            w[x] += ',';
        }
        p = mp2[a];
        for (auto y: p) {
//                    cout<<y<<endl;
            if (vis[y]==0) {
                q.push(y);
                vis[y] = 1;
            }
        }
        mp2[a].clear();
        if (x+1 < sz && vis[x+1] == 0) {
            a = v[x + 1]; k = a.size();
            if (a[k-1] == ',' || a[k-1] == '.') {
                a.erase(k-1, 1);
            }
//            cout<<a<<endl;
            p = mp[a];
            for(auto y: p) {
                if (y - 1 >= 0 && vis[y-1] == 0) {
                    q.push(y-1);
                    vis[y-1] = 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: 1ms
memory: 3632kb

Test #2:

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

Test #3:

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

Test #4:

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

Test #5:

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

Test #6:

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

Test #7:

score: 0
Accepted
time: 222ms
memory: 42688kb

Test #8:

score: 0
Accepted
time: 181ms
memory: 42748kb

Test #9:

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

Test #10:

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

Test #11:

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

Test #12:

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

Test #13:

score: -100
Wrong Answer
time: 2ms
memory: 3724kb