QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#201550 | #5151. Bottle Flip | SolitaryDream# | WA | 1ms | 3864kb | C++17 | 3.0kb | 2023-10-05 15:06:20 | 2023-10-05 15:06:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 510;
namespace Flow {
const int N = 1010;
const int M = 1e5 + 10;
int tot = 1;
int a[M], c[M], ne[M], fi[N];
inline void _Adde(int x, int y, int z) {
a[++tot] = y; ne[tot] = fi[x]; fi[x] = tot; c[tot] = z;
}
inline void Adde(int x, int y, int z) {
printf("%d -> %d %d\n", x, y, z);
_Adde(x, y, z); _Adde(y, x, 0);
}
int cur[N], de[N];
inline bool Bfs(int s, int t) {
memset(de + 1, 0, t * sizeof *de);
de[s] = 1;
static queue<int> q;
q.push(s);
while (!q.empty()) {
int u = q.front(); q.pop();
for (int i = fi[u]; i; i = ne[i]) if (c[i] && !de[a[i]]) {
de[a[i]] = de[u] + 1;
q.push(a[i]);
}
}
return de[t];
}
inline int Dfs(int x, int flow, int t) {
int sm = 0, tmp;
for (int &i = cur[x]; i; i = ne[i]) if (c[i] && de[a[i]] == de[x] + 1 && (tmp = Dfs(a[i], min(flow, c[i]), t))) {
c[i] -= tmp; c[i ^ 1] += tmp;
flow -= tmp; sm += tmp;
if (!sm) return flow;
}
return flow;
}
inline int Solve(int s, int t) {
int ans = 0;
while (Bfs(s, t)) {
memcpy(cur + 1, fi + 1, t * sizeof *cur);
ans += Dfs(s, 1e9, t);
}
return ans;
}
inline void Print(int n) {
for (int x = 1; x <= n; ++x) {
for (int i = fi[x]; i; i = ne[i]) if (c[i] && a[i] <= 26) {
putchar(a[i] - 1);
break;
}
}
puts("");
}
}
int n, m;
int ban[N][26], U[26], L[26], E[26];
char s[N], t[N], cho[N];
int main() {
scanf("%d%d", &n, &m); --n;
for (int i = 0; i < 26; ++i) U[i] = 1e9, L[i] = 0;
for (int k = 1; k <= n; ++k) {
scanf("%s%s", s + 1, t + 1);
static int cur[26];
memset(cur, 0, sizeof cur);
for (int i = 1; i <= m; ++i) {
if (t[i] == 'G') {
cho[i] = s[i];
++cur[t[i] - 'a'];
} else if (t[i] == 'Y') {
ban[i][s[i] - 'a'] = 1;
++cur[t[i] - 'a'];
} else {
ban[i][s[i] - 'a'] = 1;
U[s[i] - 'a'] = min(U[s[i] - 'a'], cur[i]);
}
}
for (int i = 0; i < 26; ++i) L[i] = max(L[i], cur[i]);
}
int t = 26 + n + 1;
int s1 = t++;
int s2 = t++;
for (int i = 1; i <= 26; ++i) {
Flow::Adde(s1, i, L[i - 1]);
Flow::Adde(s2, i, U[i - 1] - L[i - 1]);
}
for (int i = 1; i <= n; ++i) {
Flow::Adde(i + 26, t, 1);
if (cho[i]) Flow::Adde(cho[i] - 'a' + 1, i + 26, 1);
else {
for (int d = 0; d < 26; ++d) if (!ban[i][d]) Flow::Adde(d + 1, i + 26, 1);
}
}
int f1 = Flow::Solve(s1, t);
int f2 = Flow::Solve(s2, t);
printf("%d %d\n", f1, f2);
Flow::Print(n);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3864kb
input:
22 4 1 4
output:
48 -> 1 0 49 -> 1 1000000000 48 -> 2 0 49 -> 2 1000000000 48 -> 3 0 49 -> 3 1000000000 48 -> 4 0 49 -> 4 1000000000 48 -> 5 0 49 -> 5 1000000000 48 -> 6 0 49 -> 6 1000000000 48 -> 7 0 49 -> 7 1000000000 48 -> 8 0 49 -> 8 1000000000 48 -> 9 0 49 -> 9 1000000000 48 ...
result:
wrong answer 1st numbers differ - expected: '7.3333333', found: '48.0000000', error = '5.5454545'