QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#538161#8936. Team Arrangementucup-team4757#RE 0ms3824kbC++144.0kb2024-08-31 08:21:592024-08-31 08:22:00

Judging History

This is the latest submission verdict.

  • [2024-08-31 08:22:00]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 3824kb
  • [2024-08-31 08:21:59]
  • Submitted

answer

#include <bits/stdc++.h>

const int MAXN = 155;

const int INF  = 1e4;

int ans = - INT_MAX, tmp = 0;

namespace Dinic {
	struct Edge {
		int u, v;
		int32_t w;
		
		inline bool operator < (const Edge &a) const {
			return w > a.w;
		}
	};
	
	struct Node {
		int to, id;
		int32_t f;
	};
	
	std::vector <Edge> Tmp;
	std::vector <Node> E[MAXN];
	
	int Now[MAXN];
	
	inline void Add_Edge (const int u, const int v, const int32_t w) {
		Tmp.push_back ({u, v, w});
	}
	
	inline void add_edge (const int x) {
		E[Tmp[x].u].push_back ({Tmp[x].v, Now[Tmp[x].v] ++, Tmp[x].w});
		E[Tmp[x].v].push_back ({Tmp[x].u, Now[Tmp[x].u] ++, 0});
	}
	
	int Cur[MAXN], Dep[MAXN];
	int S = 145, T = 148;
	
	inline bool BFS () {
		memset (Cur, 0, sizeof Cur);
		memset (Dep, 0, sizeof Dep);
		std::queue <int> q; 
		q.push (S), Dep[S] = 1;
		int u;
		while (!q.empty ()) {
			u = q.front (), q.pop ();
			for (auto i : E[u]) 
				if (!Dep[i.to] && i.f) {
					Dep[i.to] = Dep[u] + 1, q.push (i.to);
					if (i.to == T) return 1;
				}
		}
		return 0;
	}
	
	inline int32_t DFS (const int x, const int32_t MAXF) {
		if (x == T || MAXF == 0) return MAXF;
		int32_t f = 0;
		for (int i = Cur[x]; i < (int) E[x].size () && f < MAXF; ++ i) {
			Cur[x] = i;
			if (Dep[E[x][i].to] == Dep[x] + 1 && E[x][i].f) {
				int32_t TmpF = DFS (E[x][i].to, std::min (MAXF - f, E[x][i].f));
				if (!TmpF) Dep[E[x][i].to] = 0;
				f += TmpF, E[x][i].f -= TmpF, E[E[x][i].to][E[x][i].id].f += TmpF;
			}
		}
		return f;
	}
	
	inline int32_t Solve () {
		int32_t f = 0;
		while (BFS ()) f += DFS (S, INF);
		return f;
	}
	
	inline int32_t dinic () {
		sort (Tmp.begin(), Tmp.end());
		int32_t Ans = 0;
		for (int i = 1e9, j = 0; j < (int) Tmp.size(); i /= 20) {
			while (Tmp[j].w >= i && j < (int) Tmp.size()) add_edge (j), ++ j;
			Ans += Solve ();
		}
		return Ans;
	}
}

struct nod {
	std::vector <int> k;
	int32_t w;
	
	inline bool operator < (const nod &a) const {
		return w < a.w;
	}
};

std::vector <int> v;
std::vector <nod> t;
int l[MAXN], r[MAXN], N;
int w[MAXN], stu[MAXN], tea[MAXN];

inline int Calc () {
	int ret = 0;
	for (auto i : v) ret += w[i];
	return ret;
}

inline void Add () {
	t.push_back ({v, Calc ()});
}

int n;
int c1, c2, c3, c4, c5;

inline int G (const int x, const int f = 0) {
	return x + f * 60;
}

inline void Solve () {
	if ((tmp = Calc ()) <= ans) return ++ c1, void ();
	for (auto i : v) if (stu[i] < i) return ++ c2, void ();
	for (int i = 1; i <= n; ++ i) tea[i] = 0;
	for (auto i : v) tea[i] = 1;
	for (int i = 1; i <= n; ++ i) tea[i] += tea[i - 1];
	for (int i = 1; i <= n; ++ i) 
		if (tea[r[i]] - tea[l[i] - 1] == 0)	
			return ++ c3, void ();
	
	Dinic::Tmp.clear ();
	for (int i = 1; i <= 150; ++ i) Dinic::E[i].clear ();
	
	
//	Dinic::tot = 1;
	
	for (int i = 1; i <= n; ++ i) Dinic::Add_Edge (Dinic::S, G (i, 0), 1);
	for (int i = 0; i < (int) v.size (); ++ i) Dinic::Add_Edge (G (i + 1, 1), Dinic::T, v[i]);
	for (int i = 1; i <= n; ++ i)
		for (int k = 0; k < (int) v.size (); ++ k)
			if (l[i] <= v[k] && v[k] <= r[i])
				Dinic::Add_Edge (G (i, 0), G (k + 1, 1), 1);
	
	int MaxF = Dinic::dinic ();
	
	if (MaxF == n) ans = tmp, ++ c4;
	else ++ c5;
}

inline void dfs (const int n, const int lst = 1) {
	if (n == 0) return Add (), void ();
	for (int i = lst; i <= n; ++ i) v.push_back (i), dfs (n - i, i), v.pop_back ();
}

inline void solve () {
	
	std::sort (t.begin (), t.end ());
	
	for (int i = t.size () - 1; i >= 0; -- i) {
		v = t[i].k, Solve ();
		if (ans == t[i].w) return ;
	}
}

int main () {
	
	std::cin >> n;
	
	for (int i = 1; i <= n; ++ i) std::cin >> l[i] >> r[i], ++ stu[l[i]], -- stu[r[i] + 1];
	 
	for (int i = 1; i <= n; ++ i) std::cin >> w[i];
	
	for (int i = 1; i <= n; ++ i) stu[i] += stu[i - 1];
	
	dfs (n), solve ();
	
	std::cout << (ans == - INT_MAX ? "impossible" : std::to_string (ans)) << '\n';
	
	std::cerr << t.size () << ' ' << c1 << ' ' << c2 << ' ' << c3 << ' ' << c4 << ' ' << c5 << '\n';
	
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3824kb

input:

3
2 3
1 2
2 2
4 5 100

output:

9

result:

ok single line: '9'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

3
1 3
3 3
2 3
1 1 100

output:

100

result:

ok single line: '100'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3532kb

input:

2
1 1
2 2
1 1

output:

impossible

result:

ok single line: 'impossible'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3820kb

input:

3
2 3
1 2
2 2
-100 -200 100000

output:

-300

result:

ok single line: '-300'

Test #5:

score: -100
Runtime Error

input:

9
1 4
2 5
3 4
1 5
1 1
2 5
3 5
1 3
1 1
1 1 1 1 1 1 1 1 1

output:

6

result: