QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#201581 | #5151. Bottle Flip | SolitaryDream# | WA | 1ms | 3704kb | C++17 | 3.2kb | 2023-10-05 15:15:55 | 2023-10-05 15:15:57 |
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) {
if (x == t) return flow;
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 (!flow) return sm;
}
return sm;
}
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 + 26]; i; i = ne[i]) if (c[i] && a[i] <= 26) {
putchar(a[i] - 1 + 'a');
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[s[i] - 'a'];
} else if (t[i] == 'Y') {
ban[i][s[i] - 'a'] = 1;
++cur[s[i] - 'a'];
} else {
ban[i][s[i] - 'a'] = 1;
}
}
for (int i = 1; i <= m; ++i) if (t[i] == 'B') {
U[s[i] - 'a'] = min(U[s[i] - 'a'], cur[s[i] - 'a']);
}
for (int i = 0; i < 26; ++i) L[i] = max(L[i], cur[i]);
}
for (int i = 0; i < 26; ++i) printf("%c: %d %d\n", i + 'a', L[i], U[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;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3704kb
input:
22 4 1 4
output:
a: 0 1000000000 b: 0 1000000000 c: 0 1000000000 d: 0 1000000000 e: 0 1000000000 f: 0 1000000000 g: 0 1000000000 h: 0 1000000000 i: 0 1000000000 j: 0 1000000000 k: 0 1 l: 0 1000000000 m: 0 1000000000 n: 0 1 o: 0 1000000000 p: 0 1000000000 q: 0 1000000000 r: 0 1000000000 s: 0 1000000000 t: 1 100000000...
result:
wrong output format Expected double, but "a:" found