QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#216741#2428. Comma SprinklerSwarthmore#AC ✓631ms80488kbC++202.0kb2023-10-15 21:59:442023-10-15 21:59:44

Judging History

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

  • [2023-10-15 21:59:44]
  • 评测
  • 测评结果:AC
  • 用时:631ms
  • 内存:80488kb
  • [2023-10-15 21:59:44]
  • 提交

answer

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld; // change to double if appropriate
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define F0Rd(i, a) for (int i = (a) - 1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)
#define sz(x) (int)(x).size()
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

const char nl = '\n';

void solve() {
	string line;
	getline(cin, line);
	stringstream ss(line);
	vector<string> v, words;
	string s;
	while (ss >> s) {
		v.push_back(s);
		string t = s;
		if (t.back() == ',' || t.back() == '.') t.pop_back();
		words.push_back(t);
	}

	map<pair<string, int>, vector<string>> adj;
	// 0 = fwd, 1 = back
	queue<pair<string, int>> q;
	set<pair<string, int>> S;
	F0R(i, sz(v)) {
		if (i + 1 < sz(v)) {
			if (v[i].back() != '.') {
				adj[{words[i], 0}].push_back(words[i+1]);
				adj[{words[i+1], 1}].push_back(words[i]);
			}
			if (v[i].back() == ',') {
                if (!S.count({words[i], 0})) {
                    q.push({words[i], 0});
                    S.insert({words[i], 0});
                }
			}
		}
	}
	while (!q.empty()) {
		auto [t, i] = q.front(); q.pop();
		for (auto s: adj[{t, i}]) {
			if (!S.count({s, i^1})) {
				S.insert({s, i^1});
				q.push({s, i^1});
			}
		}
	}

	F0R(i, sz(v)-1) {
		if (v[i].back() == '.') cout << v[i] << ' ';
		else if (S.count({words[i], 0})) {
			cout << words[i] << ", ";
		}
		else cout << words[i] << ' ';
	}
	cout << v.back() << '\n';

}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	solve();
	return 0;
}

Details

Test #1:

score: 100
Accepted
time: 0ms
memory: 3620kb

Test #2:

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

Test #3:

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

Test #4:

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

Test #5:

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

Test #6:

score: 0
Accepted
time: 75ms
memory: 75240kb

Test #7:

score: 0
Accepted
time: 201ms
memory: 63328kb

Test #8:

score: 0
Accepted
time: 206ms
memory: 65808kb

Test #9:

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

Test #10:

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

Test #11:

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

Test #12:

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

Test #13:

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

Test #14:

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

Test #15:

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

Test #16:

score: 0
Accepted
time: 217ms
memory: 66020kb

Test #17:

score: 0
Accepted
time: 356ms
memory: 64964kb

Test #18:

score: 0
Accepted
time: 574ms
memory: 80488kb

Test #19:

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

Test #20:

score: 0
Accepted
time: 563ms
memory: 80252kb

Test #21:

score: 0
Accepted
time: 362ms
memory: 71176kb

Test #22:

score: 0
Accepted
time: 279ms
memory: 62904kb

Test #23:

score: 0
Accepted
time: 26ms
memory: 19744kb

Test #24:

score: 0
Accepted
time: 591ms
memory: 76692kb

Test #25:

score: 0
Accepted
time: 631ms
memory: 77216kb

Test #26:

score: 0
Accepted
time: 220ms
memory: 46856kb

Test #27:

score: 0
Accepted
time: 22ms
memory: 18712kb

Test #28:

score: 0
Accepted
time: 436ms
memory: 64924kb

Test #29:

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

Test #30:

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

Test #31:

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

Test #32:

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

Test #33:

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

Test #34:

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

Test #35:

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

Test #36:

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

Test #37:

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

Test #38:

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

Test #39:

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

Test #40:

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

Test #41:

score: 0
Accepted
time: 13ms
memory: 8172kb

Test #42:

score: 0
Accepted
time: 8ms
memory: 8060kb

Test #43:

score: 0
Accepted
time: 13ms
memory: 8000kb

Test #44:

score: 0
Accepted
time: 13ms
memory: 8224kb

Test #45:

score: 0
Accepted
time: 13ms
memory: 8160kb

Test #46:

score: 0
Accepted
time: 13ms
memory: 8164kb

Test #47:

score: 0
Accepted
time: 120ms
memory: 29240kb

Test #48:

score: 0
Accepted
time: 118ms
memory: 29272kb

Test #49:

score: 0
Accepted
time: 126ms
memory: 29316kb

Test #50:

score: 0
Accepted
time: 59ms
memory: 22180kb

Test #51:

score: 0
Accepted
time: 60ms
memory: 20500kb

Test #52:

score: 0
Accepted
time: 68ms
memory: 21900kb

Test #53:

score: 0
Accepted
time: 243ms
memory: 50012kb

Test #54:

score: 0
Accepted
time: 231ms
memory: 49404kb

Test #55:

score: 0
Accepted
time: 223ms
memory: 49812kb

Test #56:

score: 0
Accepted
time: 186ms
memory: 43136kb

Test #57:

score: 0
Accepted
time: 192ms
memory: 46176kb

Test #58:

score: 0
Accepted
time: 190ms
memory: 44044kb

Test #59:

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

Test #60:

score: 0
Accepted
time: 4ms
memory: 9280kb

Test #61:

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

Test #62:

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