QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#56053 | #2428. Comma Sprinkler | captured# | WA | 213ms | 57632kb | C++ | 3.9kb | 2022-10-16 18:00:42 | 2022-10-16 18:00:43 |
Judging History
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<ll>> mp, mp2;
vector<ll> p;
vector<string> w, v;
queue<ll> 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() > 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());
w.pb(b);
v.pb(a);
}
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;
}
Details
Test #1:
score: 100
Accepted
time: 2ms
memory: 3652kb
Test #2:
score: 0
Accepted
time: 2ms
memory: 3592kb
Test #3:
score: 0
Accepted
time: 2ms
memory: 3640kb
Test #4:
score: 0
Accepted
time: 2ms
memory: 3552kb
Test #5:
score: 0
Accepted
time: 2ms
memory: 3568kb
Test #6:
score: 0
Accepted
time: 84ms
memory: 57632kb
Test #7:
score: 0
Accepted
time: 213ms
memory: 43220kb
Test #8:
score: 0
Accepted
time: 199ms
memory: 43220kb
Test #9:
score: 0
Accepted
time: 2ms
memory: 3544kb
Test #10:
score: 0
Accepted
time: 2ms
memory: 3592kb
Test #11:
score: 0
Accepted
time: 2ms
memory: 3616kb
Test #12:
score: 0
Accepted
time: 2ms
memory: 3644kb
Test #13:
score: -100
Wrong Answer
time: 2ms
memory: 3744kb