Even if I did not have the most difficult questions, I also encountered several disgusting questions this year.
I will not briefly describe the ideas of the question.
Let's talk about the problem.
That is... If the array on your side is small, it is TLE. That's right. It's TLE.
I handed in 50 posts last night and T. I changed the DINIC code more than 10 times from start to end. Later I lost my temper.
I wrote it again from the beginning when I sent it again this morning. This time, with the explosive mentality, the array was too large, and I did not expect.
I am XXXXXXXXX.
Then I changed the array size to T.
In an instant, I took out the code from last night and changed the array size to.
Then... No more... I went to dinner...
[Cpp]
# Include <iostream>
# Include <cstdio>
# Include <algorithm>
# Include <string>
# Include <cmath>
# Include <cstring>
# Include <queue>
# Include <set>
# Include <vector>
# Include <stack>
# Include <map>
# Include <iomanip>
# Define PI acos (-1.0)
# Define Max 100005 // change this to 1 W. You will know it when you try it. Test it.
# Define inf 1 <28
# Define LL (x) (x <1)
# Define RR (x) (x <1 | 1)
# Define REP (I, s, t) for (int I = (s); I <= (t); ++ I)
# Define ll long
# Define mem (a, B) memset (a, B, sizeof ())
# Define mp (a, B) make_pair (a, B)
Using namespace std;
Struct kdq
{
Int s, e, l, next;
} Ed [Max];
Int head [1100], num;
Void init ()
{
Mem (head,-1 );
Num = 0;
}
Void add (int s, int e, int l)
{
Ed [num]. s = s;
Ed [num]. e = e;
Ed [num]. l = l;
Ed [num]. next = head [s];
Head [s] = num ++;
Ed [num]. s = e;
Ed [num]. e = s;
Ed [num]. l = 0;
Ed [num]. next = head [e];
Head [e] = num ++;
}
Int cow [Max] [100];
Int w [Max];
Int n, m;
Int S, T;
Void build (int k, int k1)
{
S = 0;
T = n + m + 1;
REP (I, 1, n)
{
REP (j, k, k1)
Add (cow [I] [j], I + m, 1 );
Add (I + m, T, 1 );
}
REP (I, 1, m) add (S, I, w [I]);
}
Int deep [1100];
Int qe [Max * 100];
Int dinic_bfs ()
{
Mem (deep,-1 );
Deep [S] = 0;
Int h = 0, t = 0;
Qe [h ++] = S;
While (h> t)
{
Int tt = qe [t ++];
For (int I = head [tt]; ~ I; I = ed [I]. next)
{
Int e = ed [I]. e;
Int l = ed [I]. l;
If (l> 0 & deep [e] =-1)
{
Deep [e] = deep [tt] + 1;
Qe [h ++] = e;
}
}
}
Return deep [T]! =-1;
}
Int dinic_dfs (int now, int f)
{
If (now = T) return f;
Int flow = 0;
For (int I = head [now]; ~ I; I = ed [I]. next)
{
Int e = ed [I]. e;
Int l = ed [I]. l;
If (l> 0 & (f-flow)> 0 & deep [e] = deep [now] + 1)
{
Int mm = min (l, f-flow );
Int nn = dinic_dfs (e, mm );
Flow + = nn;
Ed [I]. l-= nn;
Ed [I ^ 1]. l + = nn;
}
}
If (! Flow) deep [now] =-2;
Return flow;
}
Int dinic ()
{
Int flow = 0;
While (dinic_bfs ())
{
Flow + = dinic_dfs (S, inf );
}
Return flow;
}
Int solve ()
{
Int ans = inf;
REP (I, 1, m)
{
REP (j, I, m)
{
Init ();
Build (I, j );
Int aa = dinic ();
If (aa = n ){
Ans = min (ans, j-I + 1 );
If (ans = 1)
Return ans;
}
}
}
Return ans;
}
Int main ()
{
# Ifndef ONLINE_JUDGE
Freopen ("acm.txt", "r", stdin );
# Endif
Scanf ("% d", & n, & m );
REP (I, 1, n) REP (j, 1, m) scanf ("% d", & cow [I] [j]);
REP (I, 1, m) scanf ("% d", & w [I]);
Printf ("% d \ n", solve ());
Return 0;
}
# Include <iostream>
# Include <cstdio>
# Include <algorithm>
# Include <string>
# Include <cmath>
# Include <cstring>
# Include <queue>
# Include <set>
# Include <vector>
# Include <stack>
# Include <map>
# Include <iomanip>
# Define PI acos (-1.0)
# Define Max 100005 // change this to 1 W. You will know it when you try it. Test it.
# Define inf 1 <28
# Define LL (x) (x <1)
# Define RR (x) (x <1 | 1)
# Define REP (I, s, t) for (int I = (s); I <= (t); ++ I)
# Define ll long
# Define mem (a, B) memset (a, B, sizeof ())
# Define mp (a, B) make_pair (a, B)
Using namespace std;
Struct kdq
{
Int s, e, l, next;
} Ed [Max];
Int head [1100], num;
Void init ()
{
Mem (head,-1 );
Num = 0;
}
Void add (int s, int e, int l)
{
Ed [num]. s = s;
Ed [num]. e = e;
Ed [num]. l = l;
Ed [num]. next = head [s];
Head [s] = num ++;
Ed [num]. s = e;
Ed [num]. e = s;
Ed [num]. l = 0;
Ed [num]. next = head [e];
Head [e] = num ++;
}
Int cow [Max] [100];
Int w [Max];
Int n, m;
Int S, T;
Void build (int k, int k1)
{
S = 0;
T = n + m + 1;
REP (I, 1, n)
{
REP (j, k, k1)
Add (cow [I] [j], I + m, 1 );
Add (I + m, T, 1 );
}
REP (I, 1, m) add (S, I, w [I]);
}
Int deep [1100];
Int qe [Max * 100];
Int dinic_bfs ()
{
Mem (deep,-1 );
Deep [S] = 0;
Int h = 0, t = 0;
Qe [h ++] = S;
While (h> t)
{
Int tt = qe [t ++];
For (int I = head [tt]; ~ I; I = ed [I]. next)
{
Int e = ed [I]. e;
Int l = ed [I]. l;
If (l> 0 & deep [e] =-1)
{
Deep [e] = deep [tt] + 1;
Qe [h ++] = e;
}
}
}
Return deep [T]! =-1;
}
Int dinic_dfs (int now, int f)
{
If (now = T) return f;
Int flow = 0;
For (int I = head [now]; ~ I; I = ed [I]. next)
{
Int e = ed [I]. e;
Int l = ed [I]. l;
If (l> 0 & (f-flow)> 0 & deep [e] = deep [now] + 1)
{
Int mm = min (l, f-flow );
Int nn = dinic_dfs (e, mm );
Flow + = nn;
Ed [I]. l-= nn;
Ed [I ^ 1]. l + = nn;
}
}
If (! Flow) deep [now] =-2;
Return flow;
}
Int dinic ()
{
Int flow = 0;
While (dinic_bfs ())
{
Flow + = dinic_dfs (S, inf );
}
Return flow;
}
Int solve ()
{
Int ans = inf;
REP (I, 1, m)
{
REP (j, I, m)
{
Init ();
Build (I, j );
Int aa = dinic ();
If (aa = n ){
Ans = min (ans, j-I + 1 );
If (ans = 1)
Return ans;
}
}
}
Return ans;
}
Int main ()
{
# Ifndef ONLINE_JUDGE
Freopen ("acm.txt", "r", stdin );
# Endif
Scanf ("% d", & n, & m );
REP (I, 1, n) REP (j, 1, m) scanf ("% d", & cow [I] [j]);
REP (I, 1, m) scanf ("% d", & w [I]);
Printf ("% d \ n", solve ());
Return 0;
}