QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#56034 | #2428. Comma Sprinkler | captured# | TL | 3ms | 3724kb | C++ | 4.1kb | 2022-10-16 17:03:51 | 2022-10-16 17:03:54 |
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<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());
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 (a[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;
}
}
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;
}
}
}
}
s = "";
for (auto x : w) {
if (s.size() > 0) s += ' ';
s += x;
}
cout<<s<<endl;
}
Details
Test #1:
score: 100
Accepted
time: 3ms
memory: 3544kb
Test #2:
score: 0
Accepted
time: 2ms
memory: 3636kb
Test #3:
score: 0
Accepted
time: 0ms
memory: 3496kb
Test #4:
score: 0
Accepted
time: 2ms
memory: 3568kb
Test #5:
score: 0
Accepted
time: 2ms
memory: 3724kb
Test #6:
score: -100
Time Limit Exceeded