QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#325176 | #5615. Two Charts Become One | tom0727 | AC ✓ | 36ms | 126200kb | C++20 | 6.9kb | 2024-02-11 05:26:53 | 2024-02-11 05:26:54 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#if __cplusplus >= 201103L
struct pairhash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
template<class T, class U>
size_t operator() (const pair<T,U> &p) const {
static const uint64_t FIXED_RANDOM = (uint64_t)chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(p.first + FIXED_RANDOM) ^ splitmix64(p.second+ FIXED_RANDOM);
}
};
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = (uint64_t)chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
inline int randint(int l, int r) {
return uniform_int_distribution<int>(l,r)(rng);
}
inline double randdouble(double l, double r) {
return uniform_real_distribution<double>(l,r)(rng);
}
inline long long randll(long long l, long long r) {
mt19937_64 rng2((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
return uniform_int_distribution<long long>(l, r)(rng2);
}
#endif
#ifndef ONLINE_JUDGE
# define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
# define LOG(x) 0
#endif
#define fastio ios::sync_with_stdio(false); cin.tie(0);
#define ll long long
#define ull unsigned long long
#define ll128 __int128_t
#define PI 3.14159265358979323846
#define abs(a) ((a>0)?a:-(a))
#define pii pair<int,int>
#define pll pair<ll,ll>
const long double pi = acos(-1.0);
const long double eps = (double)1e-10;
// const int mod = 1e9+7;
int mod;
template<class T>
T qpow(T a, int b) {
T res = 1;
while (b) {
if (b & 1) res *= a;
a *= a;
b >>= 1;
}
return res;
}
int norm(int x) {
if (x < 0) {
x += mod;
}
if (x >= mod) {
x -= mod;
}
return x;
}
struct Z {
int x;
Z(int x = 0) : x(norm(x)) {}
Z(ll x) : x(norm((int)(x % mod))) {}
int val() const {
return x;
}
Z operator-() const {
return Z(norm(mod - x));
}
Z inv() const {
assert(x != 0);
return qpow(*this, mod - 2);
}
Z &operator*=(const Z &rhs) {
x = (int)((ll)(x) * rhs.x % mod);
return *this;
}
Z &operator+=(const Z &rhs) {
x = norm(x + rhs.x);
return *this;
}
Z &operator-=(const Z &rhs) {
x = norm(x - rhs.x);
return *this;
}
Z &operator/=(const Z &rhs) {
return *this *= rhs.inv();
}
friend Z operator*(const Z &lhs, const Z &rhs) {
Z res = lhs;
res *= rhs;
return res;
}
friend Z operator+(const Z &lhs, const Z &rhs) {
Z res = lhs;
res += rhs;
return res;
}
friend Z operator-(const Z &lhs, const Z &rhs) {
Z res = lhs;
res -= rhs;
return res;
}
friend Z operator/(const Z &lhs, const Z &rhs) {
Z res = lhs;
res /= rhs;
return res;
}
friend std::istream &operator>>(std::istream &is, Z &a) {
ll v;
is >> v;
a = Z(v);
return is;
}
friend std::ostream &operator<<(std::ostream &os, const Z &a) {
return os << a.val();
}
};
const int maxn = 1e6+5;
const int maxm = 1e6+5;
ull base = rng();
ull H(ull x){
return x*x*x*19890535+19260817;
}
ull F(ull x){
return H(x&((1ll<<32)-1))+H(x>>32);
}
struct Sol {
int sz[maxn];
vector<int> cent;
ull h[maxn];
int cur_sz = 0;
void dfs1(int u, int p) {
sz[u] = 1;
int mx = 0;
for (int v : adj[u]) {
if (v == p) continue;
dfs1(v, u);
sz[u] += sz[v];
mx = max(mx, sz[v]);
}
mx = max(mx, cur_sz - sz[u]);
if (mx <= cur_sz / 2) cent.push_back(u);
}
vector<ull> ha[maxn];
void dfs2(int u, int p) {
h[u] = base * u;
for (int v : adj[u]) {
if (v == p) continue;
dfs2(v, u);
h[u] += F(h[v]);
}
}
vector<int> adj[maxn];
pair<vector<ull>,int> solve() {
string S, s;
getline(cin, S);
for (char c : S) {
if (c != '(' && c != ')' && !(c>='0' && c<='9')) {
continue;
}
s.push_back(c);
}
vector<int> vec;
int cur = 0;
for (char c : s) {
if (c == '(') {
if (cur) vec.push_back(cur);
cur = 0;
vec.push_back(-1);
} else if (c == ')') {
if (cur) vec.push_back(cur);
cur = 0;
vec.push_back(-2);
} else {
cur = cur * 10 + c - '0';
}
}
if (cur) { // only one
return {{}, cur};
}
// for (int x : vec) cout << x << " ";
// cout << "\n";
vector<int> st;
for (int x : vec) {
if (x == -2) {
// assert(vec.size() && vec.back() > 0);
int v = st.back();
st.pop_back(); // v
// assert(vec.size() && vec.back() == -1);
st.pop_back(); // -1
// assert(vec.size() && vec.back() > 0);
int u = st.back();
adj[u].push_back(v);
adj[v].push_back(u);
} else {
if (x != -1) cur_sz++;
st.push_back(x);
}
}
vector<ull> ha;
// assert(vec.size());
int rt = st.back();
dfs1(rt, 0);
for (int ce : cent) {
dfs2(ce, 0);
ha.push_back(h[ce]);
// LOG(h[ce]);
}
return {ha, 0};
}
} sol1, sol2;
int main() {
auto res1 = sol1.solve(), res2 = sol2.solve();
bool ok = 0;
if (res1.first.size() == 0 && res2.first.size() == 0) {
ok = (res1.second == res2.second);
} else {
if (res1.first.size() == 0 || res2.first.size() == 0) {
ok = 0;
} else {
for (ull h1 : res1.first) {
for (ull h2 : res2.first) {
if (h1 == h2) ok = 1;
}
}
}
}
cout << (ok ? "Yes" : "No") << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 8ms
memory: 104184kb
input:
11 (10) (12 (13) (17) (28)) 11 (12 (17) (28) (13)) (10)
output:
Yes
result:
ok single line: 'Yes'
Test #2:
score: 0
Accepted
time: 8ms
memory: 104424kb
input:
11 ( 10 ) ( 12 ) 11(10(12))
output:
No
result:
ok single line: 'No'
Test #3:
score: 0
Accepted
time: 3ms
memory: 105476kb
input:
11 (10) (12) 11 (10) (13)
output:
No
result:
ok single line: 'No'
Test #4:
score: 0
Accepted
time: 33ms
memory: 124100kb
input:
289384 (694459 (751708 (887544 (519034 (207488 (373389 ) (912072 ) (191461 ) (91909 ) (5562 ) (705802 ) (469815 ) (726477 ) ) (204098 (530445 ) (655063 ) (156343 ) (980456 ) (186944 ) (198850 ) ) ) (502461 (427161 (615081 ) (801892 ) (594639 ) (786804 ) (811554 ) (810699 ) (935475 ) (717636 ) ) (537...
output:
No
result:
ok single line: 'No'
Test #5:
score: 0
Accepted
time: 21ms
memory: 121640kb
input:
289384 (694459 (751708 (887544 (519034 (207488 (373389 (912072 (191461 (91909 ) (5562 ) ) (705802 (469815 ) (726477 ) (204098 ) (530445 ) (655063 ) ) ) (156343 (980456 (186944 ) (198850 ) ) (502461 (427161 ) (615081 ) (801892 ) (594639 ) (786804 ) ) (811554 (810699 ) (935475 ) (717636 ) (537132 ) ) ...
output:
Yes
result:
ok single line: 'Yes'
Test #6:
score: 0
Accepted
time: 11ms
memory: 121628kb
input:
289384 (694459 (751708 (887544 (519034 (207488 (373389 (912072 (191461 (91909 ) (5562 ) ) (705802 (469815 ) (726477 ) (204098 ) (530445 ) (655063 ) ) ) (156343 (980456 (186944 ) (198850 ) ) (502461 (427161 ) (615081 ) (801892 ) (594639 ) (786804 ) ) (811554 (810699 ) (935475 ) (717636 ) (537132 ) ) ...
output:
No
result:
ok single line: 'No'
Test #7:
score: 0
Accepted
time: 12ms
memory: 121660kb
input:
289384 (694459 (751708 (887544 (519034 (207488 (373389 (912072 (191461 (91909 (5562 ) ) (705802 (469815 ) (726477 ) ) (204098 (530445 ) (655063 ) (156343 ) (980456 ) ) ) (186944 (198850 (502461 ) (427161 ) ) (615081 (801892 ) ) (594639 (786804 ) (811554 ) (810699 ) ) ) (935475 (717636 (537132 ) (678...
output:
Yes
result:
ok single line: 'Yes'
Test #8:
score: 0
Accepted
time: 16ms
memory: 121760kb
input:
289384 (694459 (751708 (887544 (519034 (207488 (373389 (912072 (191461 (91909 (5562 ) ) (705802 (469815 ) (726477 ) ) (204098 (530445 ) (655063 ) (156343 ) (980456 ) ) ) (186944 (198850 (502461 ) (427161 ) ) (615081 (801892 ) ) (594639 (786804 ) (811554 ) (810699 ) ) ) (935475 (717636 (537132 ) (678...
output:
No
result:
ok single line: 'No'
Test #9:
score: 0
Accepted
time: 15ms
memory: 121896kb
input:
289384 (694459 (751708 (887544 (519034 (207488 (373389 (912072 (191461 (91909 (5562 (705802 (469815 (726477 (204098 (530445 (655063 (156343 (980456 (186944 (198850 ) ) ) (502461 (427161 (615081 ) (801892 ) ) (594639 (786804 ) ) ) ) ) ) (811554 (810699 (935475 (717636 (537132 (678641 ) (777412 ) ) (6...
output:
Yes
result:
ok single line: 'Yes'
Test #10:
score: 0
Accepted
time: 16ms
memory: 121612kb
input:
289384 (694459 (751708 (887544 (519034 (207488 (373389 (912072 (191461 (91909 (5562 (705802 (469815 (726477 (204098 (530445 (655063 (156343 (980456 (186944 (198850 ) ) ) (502461 (427161 (615081 ) (801892 ) ) (594639 (786804 ) ) ) ) ) ) (811554 (810699 (935475 (717636 (537132 (678641 ) (777412 ) ) (6...
output:
No
result:
ok single line: 'No'
Test #11:
score: 0
Accepted
time: 7ms
memory: 104760kb
input:
10 10
output:
Yes
result:
ok single line: 'Yes'
Test #12:
score: 0
Accepted
time: 12ms
memory: 104424kb
input:
10 1
output:
No
result:
ok single line: 'No'
Test #13:
score: 0
Accepted
time: 36ms
memory: 126200kb
input:
289384 (638630 ) (239184 ) (765440 ) (646178 (372606 ) (910028 ) (190096 ) (91605 ) (5527 ) (705508 ) (469479 ) (726199 ) (201953 ) (529344 ) (653748 ) (154974 ) (979397 ) (186316 ) (197719 ) (501602 ) (426553 ) (613347 ) (801743 ) (593510 ) (786392 ) (809643 ) (810562 ) (934493 ) (717125 ) (535195 ...
output:
Yes
result:
ok single line: 'Yes'
Test #14:
score: 0
Accepted
time: 32ms
memory: 126056kb
input:
289384 (638630 ) (239184 ) (765440 ) (646178 (372606 ) (910028 ) (190096 ) (91605 ) (5527 ) (705508 ) (469479 ) (726199 ) (201953 ) (529344 ) (653748 ) (154974 ) (979397 ) (186316 ) (197719 ) (501602 ) (426553 ) (613347 ) (801743 ) (593510 ) (786392 ) (809643 ) (810562 ) (934493 ) (717125 ) (535195 ...
output:
No
result:
ok single line: 'No'
Test #15:
score: 0
Accepted
time: 35ms
memory: 126188kb
input:
289384 (638630 ) (239184 ) (765440 ) (646178 (372606 ) (910028 ) (190096 ) (91605 ) (5527 ) (705508 ) (469479 ) (726199 ) (201953 ) (529344 ) (653748 ) (154974 ) (979397 ) (186316 ) (197719 ) (501602 ) (426553 ) (613347 ) (801743 ) (593510 ) (786392 ) (809643 ) (810562 ) (934493 ) (717125 ) (535195 ...
output:
No
result:
ok single line: 'No'
Test #16:
score: 0
Accepted
time: 32ms
memory: 126100kb
input:
289384 (638630 ) (239184 ) (765440 ) (646178 (372606 ) (910028 ) (190096 ) (91605 ) (5527 ) (705508 ) (469479 ) (726199 ) (201953 ) (529344 ) (653748 ) (154974 ) (979397 ) (186316 ) (197719 ) (501602 ) (426553 ) (613347 ) (801743 ) (593510 ) (786392 ) (809643 ) (810562 ) (934493 ) (717125 ) (535195 ...
output:
No
result:
ok single line: 'No'
Test #17:
score: 0
Accepted
time: 8ms
memory: 120836kb
input:
289384 (694459 (751708 (887544 (519034 (207488 (373389 (912072 (191461 (91909 (5562 (705802 (469815 (726477 (204098 (530445 (655063 (156343 (980456 (186944 (198850 (502461 (427161 (615081 (801892 (594639 (786804 (811554 (810699 (935475 (717636 (537132 (678641 (777412 (698714 (656060 (853387 (972741 ...
output:
Yes
result:
ok single line: 'Yes'
Test #18:
score: 0
Accepted
time: 10ms
memory: 104028kb
input:
384 (154 (136 (540 ) (298 ) (133 ) (273 ) (948 ) (61 ) ) (823 (792 ) (348 ) (407 ) (972 ) (916 ) (250 ) (439 ) ) (840 (414 ) (491 ) (450 ) (742 ) (963 ) (606 ) (860 ) (639 ) ) (736 (800 ) ) (591 (595 ) ) (146 (345 ) (249 ) (31 ) (914 ) (976 ) (559 ) ) ) (678 (413 (646 ) (848 ) (720 ) (835 ) (718 ) )...
output:
Yes
result:
ok single line: 'Yes'
Test #19:
score: 0
Accepted
time: 7ms
memory: 104968kb
input:
384 (154 (136 (540 ) (298 ) (133 ) (273 ) (948 ) (61 ) ) (823 (792 ) (348 ) (407 ) (972 ) (916 ) (250 ) (439 ) ) (840 (414 ) (491 ) (450 ) (742 ) (963 ) (606 ) (860 ) (639 ) ) (736 (800 ) ) (591 (595 ) ) (146 (345 ) (249 ) (31 ) (914 ) (976 ) (559 ) ) ) (678 (413 (646 ) (848 ) (720 ) (835 ) (718 ) )...
output:
No
result:
ok single line: 'No'
Test #20:
score: 0
Accepted
time: 12ms
memory: 102972kb
input:
384 (154 (136 (540 (298 (133 (273 (948 (61 (823 (792 ) ) ) ) (348 (407 (972 (916 ) (250 ) ) ) (439 (840 (414 ) (491 ) ) ) ) ) (450 (742 (963 (606 (860 ) ) (639 (736 ) ) ) (800 (591 (595 ) ) (146 (345 ) (249 ) ) ) ) (31 (914 (976 (559 ) (678 ) ) (413 (646 ) ) ) (848 (720 (835 ) ) ) ) ) ) (718 (679 (2...
output:
Yes
result:
ok single line: 'Yes'
Test #21:
score: 0
Accepted
time: 12ms
memory: 105172kb
input:
384 (154 (136 (540 (298 (133 (273 (948 (61 (823 (792 ) ) ) ) (348 (407 (972 (916 ) (250 ) ) ) (439 (840 (414 ) (491 ) ) ) ) ) (450 (742 (963 (606 (860 ) ) (639 (736 ) ) ) (800 (591 (595 ) ) (146 (345 ) (249 ) ) ) ) (31 (914 (976 (559 ) (678 ) ) (413 (646 ) ) ) (848 (720 (835 ) ) ) ) ) ) (718 (679 (2...
output:
No
result:
ok single line: 'No'
Test #22:
score: 0
Accepted
time: 11ms
memory: 103184kb
input:
384 (707 (136 (540 (298 (133 (273 (948 (61 (823 (792 ) ) ) ) (348 (407 (972 (916 ) (250 ) ) ) (439 (840 (414 ) (491 ) ) ) ) ) (450 (742 (963 (606 (860 ) ) (639 (736 ) ) ) (800 (591 (595 ) ) (146 (345 ) (249 ) ) ) ) (31 (914 (976 (559 ) (678 ) ) (413 (646 ) ) ) (848 (720 (835 ) ) ) ) ) ) (718 (679 (2...
output:
No
result:
ok single line: 'No'
Test #23:
score: 0
Accepted
time: 28ms
memory: 124024kb
input:
289384 (694459 (751708 (887544 (519034 (207488 (373389 ) (912072 ) (191461 ) (91909 ) (5562 ) (705802 ) (469815 ) (726477 ) ) (204098 (530445 ) (655063 ) (156343 ) (980456 ) (186944 ) (198850 ) ) ) (502461 (427161 (615081 ) (801892 ) (594639 ) (786804 ) (811554 ) (810699 ) (935475 ) (717636 ) ) (537...
output:
Yes
result:
ok single line: 'Yes'