답안 #465125

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
465125 2021-08-15T08:32:23 Z prvocislo Programming Contest (POI11_pro) C++17
70 / 100
35 ms 2304 KB
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>
using namespace std;

const int maxn = 505;
int deg_o[maxn], match_z[maxn];
vector<int> g_o[maxn], g_z[maxn];
int vis_o[maxn], vis_z[maxn];
bool dfs(int o1, int d)
{
	if (deg_o[o1] < d - 1) return true;
	vis_o[o1] = true;
	for (int z : g_o[o1]) if (!vis_z[z] && match_z[z] == o1)
	{
		vis_z[z] = true;
		for (int o2 : g_z[z]) if (!vis_o[o2])
		{
			if (dfs(o2, d))
			{
				match_z[z] = o2;
				deg_o[o1]--, deg_o[o2]++;
				return true;
			}
		}
	}
	return false;
}
bool cmp(int o1, int o2)
{
	return deg_o[o1] > deg_o[o2];
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int no, nz, r, t, k;
	cin >> no >> nz >> r >> t >> k;
	for (int i = 0; i < k; i++)
	{
		int o, z;
		cin >> o >> z;
		g_o[--o].push_back(--z);
		g_z[z].push_back(o);
	}
	vector<int> ord(no);
	iota(ord.begin(), ord.end(), 0);
	fill(match_z, match_z + nz, -1);
	for (int i = 0; i < no; i++) random_shuffle(g_o[i].begin(), g_o[i].end());
	for (int i = 0; i < nz; i++) random_shuffle(g_z[i].begin(), g_z[i].end());
	for (int i = 0; i < nz; i++) if (!g_z[i].empty())
	{
		match_z[i] = g_z[i][0];
		deg_o[match_z[i]]++;
	}
	bool change = true;
	while (change)
	{
		change = false;
		sort(ord.begin(), ord.end(), cmp);
		for (int i = 0; i < no; i++) vis_o[i] = false;
		for (int i = 0; i < nz; i++) vis_z[i] = false;
		for (int o : ord) if (!vis_o[o])
			change |= dfs(o, deg_o[o]);
	}
	int solved = 0, time = 0;
	for (int i = 0; i < no; i++)
	{
		deg_o[i] = min(deg_o[i], (int)g_o[i].size());
		solved += deg_o[i];
		time += r * (deg_o[i] * (deg_o[i] + 1)) / 2;
	}
	cout << solved << " " << time << "\n";
	for (int i = 0; i < nz; i++) if (match_z[i] != -1 && deg_o[match_z[i]])
	{
		deg_o[match_z[i]]--;
		cout << match_z[i] + 1 << " " << i + 1 << " " << deg_o[match_z[i]] * r << "\n";
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 716 KB Output is correct
2 Correct 5 ms 588 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 2056 KB Output is correct
2 Correct 28 ms 2140 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 2064 KB Output is correct
2 Correct 11 ms 844 KB Output is correct
3 Incorrect 1 ms 332 KB Your program assigned 471 problems but it was possible to solve only 469.
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 2304 KB Output is correct
2 Correct 14 ms 1288 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 716 KB Your program assigned 489 problems but it was possible to solve only 390.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 2108 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 860 KB Your program assigned 458 problems but it was possible to solve only 452.
2 Halted 0 ms 0 KB -