QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#490985 | #8759. 小班课 | Rong7 | WA | 0ms | 20204kb | C++14 | 3.8kb | 2024-07-25 16:56:48 | 2024-07-25 16:56:48 |
Judging History
answer
// Not afraid to dark.
#include <bits/stdc++.h>
using namespace std;
#define inline __inline__ __attribute__ ((always_inline))
namespace io {
int pos;
inline int read (int &p = pos){
static int v; static char c;
v = 1, c = getchar (), p = 0;
while (! isdigit (c)){
if (c == '-')
v = - 1;
c = getchar ();
}
while (isdigit (c)){
p = (p << 1) + (p << 3) + (c - 48);
c = getchar ();
}
return p *= v;
}
inline void write (int x){
if (x < 0)
putchar ('-'), x = - x;
static int sta[65], top;
top = 0;
do {
sta[++ top] = x % 10;
x /= 10;
} while (x);
while (top)
putchar (sta[top --] + 48);
}
inline char next_char (){
static char c;
c = getchar ();
while (c == '\n' || c == ' ' || c == '\r')
c = getchar ();
return c;
}
inline void putss (const string s){
for (int i = 0;i < (int) s.size ();++ i)
putchar (s[i]);
}
}
const int N = 500;
int n, m;
int restb, b[N + 5], a[N + 5][N + 5];
namespace EK {
const int cV = N * 2 + 5, cE = N * N * 6 + 5, inf = 0x3f3f3f3f;
int s, t;
int firs[cV], nex[cE], to[cE], w[cE], c[cE], tot;
int dis[cE], pre[cE], cur[cE], Ansflow, Mincost;
bool inque[cE];
queue < int > q;
inline void init (){
for (int i = 1;i <= t;++ i) firs[i] = 0;
tot = 1;
}
inline void Add (int u, int v, int x, int y){
++ tot;
nex[tot] = firs[u];
firs[u] = tot;
to[tot] = v;
w[tot] = x;
c[tot] = y;
++ tot;
nex[tot] = firs[v];
firs[v] = tot;
to[tot] = u;
w[tot] = 0;
c[tot] = - y;
}
inline bool Bfs (){
for (int i = 1;i <= t;++ i)
dis[i] = inf, pre[i] = 0, cur[i] = inf, inque[i] = false;
while (! q.empty ()) q.pop ();
q.push (s); inque[s] = true; dis[s] = 0;
while (! q.empty ()){
int u = q.front ();
q.pop ();
inque[u] = false;
for (int e = firs[u], v;e;e = nex[e]){
v = to[e];
if (w[e] != 0 && dis[v] > dis[u] + c[e]){
dis[v] = dis[u] + c[e];
pre[v] = e;
cur[v] = min (w[e], cur[u]);
if (! inque[v])
q.push (v);
inque[v] = true;
}
}
}
return dis[t] != inf;
}
inline void MFMC (){
Ansflow = Mincost = 0;
while (Bfs ()){
int now = t;
while (now != s){
w[pre[now]] -= cur[t];
w[pre[now] ^ 1] += cur[t];
now = to[pre[now] ^ 1];
}
Ansflow += cur[t];
Mincost += cur[t] * dis[t];
}
}
} using namespace EK;
int rep[N + 5], fe[N + 5];
bool vis[N + 5];
int res;
vector < int > ans;
inline void PUSHANS (int x){
for (int i = 1;i <= a[x][0];++ i)
if (b[a[x][i]]){ -- b[a[x][i]]; restb -= ! b[a[x][i]]; ++ res; break; }
ans.push_back (x);
vis[x] = true;
}
inline void ARKNIGHTS (){
ans.clear (), res = 0;
io::read (n), io::read (m);
restb = 0;
for (int i = 1;i <= m;++ i) restb += (bool) io::read (b[i]);
for (int i = 1;i <= n;++ i){
vis[i] = false;
io::read (a[i][0]);
for (int j = 1;j <= a[i][0];++ j) io::read (a[i][j]);
}
while (restb && (int) ans.size () < n){
int L = n - (int) ans.size (), R = restb;
s = L + R + 1, t = s + 1;
init ();
for (int i = 1, cnt = 0;i <= m;++ i)
if (! b[i]) rep[i] = 0;
else rep[i] = ++ cnt, Add (rep[i] + L, t, b[i], 0);
for (int i = 1, cnt = 0;i <= n;++ i)
if (! vis[i]){
Add (s, ++ cnt, 1, 0);
for (int j = 1, ct = 0;j <= a[i][0];++ j)
if (rep[a[i][j]]){
if (! ct) fe[i] = tot + 1;
Add (cnt, rep[a[i][j]] + L, 1, ++ ct);
}
}
MFMC ();
for (int i = 1;i <= n;++ i)
if (! vis[i] && ! w[fe[i]])
PUSHANS (i);
}
for (int i = 1;i <= n;++ i)
if (! vis[i])
PUSHANS (i);
io::write (res), putchar ('\n');
for (int i = 0;i < n;++ i)
io::write (ans[i]), putchar (' ');
putchar ('\n');
}
signed main (){
for (int T = min (io::read (), 10);T --;) ARKNIGHTS ();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 19980kb
input:
3 5 5 1 1 1 1 1 4 1 3 2 4 1 5 4 3 4 2 1 2 3 5 1 1 5 3 1 2 2 2 1 2 2 1 2 2 1 3 2 1 3 2 1 3 5 5 1 1 1 1 1 2 1 2 2 5 4 2 3 2 2 4 3 2 5 1
output:
5 2 4 5 1 3 5 5 1 2 3 4 5 2 3 4 5 1
result:
ok Correct!
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 20204kb
input:
250 2 1 2 1 1 1 1 1 1 1 0 2 2 1 1 1 1 2 2 1 2 2 0 2 2 1 2 1 2 1 1 1 1 1 1 2 1 0 0 1 2 1 0 0 2 1 2 1 1 0 1 2 1 0 0 2 1 2 1 1 1 1 1 1 1 1 1 1 2 1 0 1 2 2 2 2 0 1 1 1 2 1 1 1 0 1 1 1 0 1 2 0 1 1 1 2 2 1 1 1 1 2 1 2 2 2 1 1 2 2 1 2 2 1 1 2 0 1 1 2 2 1 2 1 1 0 2 2 2 0 1 1 1 2 1 1 1 1 1 2 1 2 0 1 1 1 1 1 ...
output:
2 1 2 0 1 2 1 2 2 1 2 1 1 0 1 0 1 1 1 2 0 1 2 1 2
result:
wrong output format Unexpected end of file - int32 expected