voidsolve(){ int _; cin >> _; for (int tc = 0; tc < _; ++tc) { int n; cin >> n; int cur = 0; for (int i = 0; i < n; ++i) { int tmp; cin >> tmp; int c = (cur + tmp) / tmp; cur = c * tmp; } cout << cur << endl; } }
voidsolve(){ int _; cin >> _; for (int tc = 0; tc < _; ++tc) { int n, m; cin >> n >> m; vector<int> data(n); for (auto &i: data) cin >> i; string str; str.resize(n); cin >> str;
vector<int> order(n); int l = 0, r = n - 1; for (int i = 0; i < n; ++i) { if (str[i] == 'L') order[i] = data[l++]; else order[i] = data[r--]; }
int cur = 1; for (int i = n - 1; i >= 0; --i) { cur = (cur * order[i]) % m; data[i] = cur; } for (int i = 0; i < n; ++i) cout << data[i] << " \n"[i == n - 1]; } }
voidsolve(){ int _; cin >> _; for (int tc = 0; tc < _; ++tc) { function<int(int, int, int &, int &)> exGcd = [&exGcd](int a, int b, int &x, int &y) { if (!b) { x = 1, y = 0; return a; } int ret = exGcd(b, a % b, y, x); y -= a / b * x; return ret; }; structedge { int a, b, v, n; };
int n, m, H; cin >> n >> m >> H; vector<int> l(n), s(n); vector<edge> edges(m * 2); vector<int> head(n + 1, -1); for (auto &i: l) cin >> i; for (auto &i: s) cin >> i;
for (int i = 0; i < m; ++i) { int u, v; cin >> u >> v;
int a = s[u - 1] - s[v - 1], b = H, x, y; int g = exGcd(a, b, x, y); if (abs(l[v - 1] - l[u - 1]) % abs(g)) continue;
a = abs(b / g); b = (a - (((l[u - 1] - l[v - 1]) / g * x) % a + a) % a) % a; edges[i << 1] = {a, b, v, head[u]}; edges[i << 1 | 1] = {a, b, u, head[v]}; head[u] = i << 1; head[v] = i << 1 | 1; }
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> q; vector<bool> visit(n + 1, false); q.emplace(0, 1); int ans = -1; while (!q.empty()) { auto [cost, cur] = q.top(); q.pop(); if (visit[cur]) continue; visit[cur] = true; if (cur == n) { ans = cost; break; } for (int e = head[cur]; ~e; e = edges[e].n) { int tmp = (cost - edges[e].b + edges[e].a - 1) / edges[e].a; int nc = tmp * edges[e].a + edges[e].b; q.emplace(nc + 1, edges[e].v); } } cout << ans << endl; } }