QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#216726 | #2428. Comma Sprinkler | Swarthmore# | TL | 1538ms | 80308kb | C++20 | 1.9kb | 2023-10-15 21:45:29 | 2023-10-15 21:45:30 |
Judging History
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() == ',') {
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3636kb
Test #2:
score: 0
Accepted
time: 0ms
memory: 3548kb
Test #3:
score: 0
Accepted
time: 0ms
memory: 3608kb
Test #4:
score: 0
Accepted
time: 0ms
memory: 3536kb
Test #5:
score: 0
Accepted
time: 0ms
memory: 3500kb
Test #6:
score: 0
Accepted
time: 70ms
memory: 74880kb
Test #7:
score: 0
Accepted
time: 209ms
memory: 64796kb
Test #8:
score: 0
Accepted
time: 196ms
memory: 64172kb
Test #9:
score: 0
Accepted
time: 0ms
memory: 3544kb
Test #10:
score: 0
Accepted
time: 0ms
memory: 3624kb
Test #11:
score: 0
Accepted
time: 1ms
memory: 3644kb
Test #12:
score: 0
Accepted
time: 0ms
memory: 3548kb
Test #13:
score: 0
Accepted
time: 1ms
memory: 3772kb
Test #14:
score: 0
Accepted
time: 0ms
memory: 3568kb
Test #15:
score: 0
Accepted
time: 0ms
memory: 3520kb
Test #16:
score: 0
Accepted
time: 1538ms
memory: 67088kb
Test #17:
score: 0
Accepted
time: 1106ms
memory: 68384kb
Test #18:
score: 0
Accepted
time: 979ms
memory: 77148kb
Test #19:
score: 0
Accepted
time: 0ms
memory: 3800kb
Test #20:
score: 0
Accepted
time: 754ms
memory: 80308kb
Test #21:
score: 0
Accepted
time: 403ms
memory: 69788kb
Test #22:
score: 0
Accepted
time: 306ms
memory: 60852kb
Test #23:
score: 0
Accepted
time: 31ms
memory: 19760kb
Test #24:
score: -100
Time Limit Exceeded