QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#63941 | #5110. Splitstream | Noobie_99 | WA | 2ms | 3328kb | C++20 | 2.4kb | 2022-11-23 19:19:25 | 2022-11-23 19:19:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cerr << "[" << __LINE__ << ' ' << #x << "]: " << (x) << endl
int main() {
cin.tie(0)->sync_with_stdio(0);
int m, n, q;
cin >> m >> n >> q;
vector<vector<int>> g(n + 3*n+1);
vector<vector<int>> g2(n + 3*n+1);
vector<int> deg(4*n+1);
for (int i=0; i<n; i++) {
char c;
int x, y, z;
cin >> c >> x >> y >> z;
if (c == 'S') {
g[n+x].push_back(i);
g[i].push_back(n+y);
g[i].push_back(n+z);
deg[i]++;
deg[n+y]++;
deg[n+z]++;
} else {
g[n+x].push_back(i);
g[n+y].push_back(i);
g[i].push_back(n+z);
deg[i] += 2;
deg[n+z]++;
}
}
for (int i=0; i<4*n+1; i++) {
for (int e : g[i]) g2[e].push_back(i);
}
vector<int> topo;
for (int i=0; i<4*n+1; i++) if (deg[i] == 0) topo.push_back(i);
vector<int> sz(g.size());
sz[n+1] = m;
for (int i=0; i<(int)topo.size(); i++) {
int e = topo[i];
if (g[e].size() == 0) continue;
if (g[e].size() == 1) sz[g[e][0]] += sz[e];
else {
sz[g[e][0]] += (sz[e]+1) / 2;
sz[g[e][1]] += (sz[e]) / 2;
}
for (int f : g[e]) {
deg[f]--;
if (deg[f] == 0) topo.push_back(f);
}
}
while (q--) {
int x, k;
cin >> x >> k;
if (sz[n+x] < k) {
cout << "none\n";
continue;
}
int cur = n+x;
while (cur != n+1) {
if (g2[cur].size() == 2) {
int a = g2[cur][0], b = g2[cur][1];
int mn = min(sz[a], sz[b]);
if (2 * mn >= k) {
if (k % 2 == 1) k = (k+1)/2, cur = a;
else k /= 2, cur = b;
} else {
k -= mn;
if (a > mn) cur = a;
else cur = b;
}
} else {
int par = g2[cur][0];
if (g[par].size() == 2) {
k *= 2;
if (cur == g[par][0]) k--;
}
cur = par;
}
}
cout << k << '\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3328kb
input:
5 8 26 M 8 9 13 S 2 4 5 S 1 2 3 M 6 5 8 S 4 9 10 S 10 14 15 S 3 6 7 S 7 11 12 2 3 2 4 3 2 3 3 4 2 4 3 5 1 5 2 6 1 6 2 7 1 7 2 8 2 8 3 9 1 9 2 10 1 10 2 11 1 11 2 12 1 13 3 13 4 14 1 14 2 15 1
output:
5 none 4 none 5 none 3 none 2 none 4 none 2 none 1 none 5 none 4 none none 2 none 5 none none
result:
wrong answer 13th lines differ - expected: '3', found: '2'