94302024-02-21 16:49:30ananászDinamitcpp17Hibás válasz 28/509ms4708 KiB
// dinamit.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

int main()
{
	long long N, M, K;
	cin >> N >> M >> K;
	vector<vector<long long>>sum(N, vector<long long>(M, 0));
	vector<vector<long long>>faradtsag(N, vector<long long>(M, 0));
	vector<vector<priority_queue<int>>>pr(N, vector<priority_queue<int>>(M));
	for (long long i = 0; i < N; i++)
	{
		for (long long j = 0; j < M; j++)
		{
			cin >> faradtsag[i][j];
		}
	}
	sum[0][0] = faradtsag[0][0];
	pr[0][0].push(faradtsag[0][0]);
	for (long long i = 1; i < M; i++)
	{
		sum[0][i] = sum[0][i - 1] + faradtsag[0][i];
		pr[0][i] = pr[0][i - 1];
		pr[0][i].push(faradtsag[0][i]);

	}
	priority_queue<int>aktf;
	priority_queue<int>akts;
	int s = 0;
	int f = 0;
	int xf;
	//int yf;
	int xs;
	//int ys;
	int kf = 0;
	int ks = 0;
	for (long long i = 1; i < N; i++)
	{
		for (long long j = 0; j < M; j++)
		{
			if (j == 0)
			{
				sum[i][j] = sum[i - 1][j] + faradtsag[i][j];
				pr[i][j] = pr[i - 1][j];
				pr[i][j].push(faradtsag[i][j]);
			}
			else
			{
				f = sum[i - 1][j] + faradtsag[i][j];
				s = sum[i][j - 1] + faradtsag[i][j];
				aktf = pr[i - 1][j];
				aktf.push(faradtsag[i][j]);
				akts = pr[i][j - 1];
				akts.push(faradtsag[i][j]);
				for (int k = 0; k < K; k++)
				{
					if (aktf.top() > 1)
					{
						kf++;
						xf = aktf.top();
						aktf.pop();
						if (xf % 2 == 0)
						{
							xf = xf / 2;
							//yf = xf;
						}
						else
						{
							xf = xf / 2;
							//yf = xf + 1;
							f--;
						}
						aktf.push(xf);
						//f -= yf;
						f -= xf;
					}
					if (akts.top() > 1)
					{
						ks++;
						xs = akts.top();
						akts.pop();
						if (xs % 2 == 0)
						{
							xs = xs / 2;
							//ys = xs;
						}
						else
						{
							xs = xs / 2;
							//ys = xs + 1;
							s--;
						}
						akts.push(xs);
						s -= xs;
					}
				}
				if (f < s)
				{
					sum[i][j] = sum[i - 1][j] + faradtsag[i][j];
					pr[i][j] = pr[i - 1][j];
					pr[i][j].push(faradtsag[i][j]);

				}
				else if (s < f)
				{
					sum[i][j] = sum[i][j - 1] + faradtsag[i][j];
					pr[i][j] = pr[i][j - 1];
					pr[i][j].push(faradtsag[i][j]);
				}
				else
				{
					if (kf < ks)
					{
						sum[i][j] = sum[i - 1][j] + faradtsag[i][j];
						pr[i][j] = pr[i - 1][j];
						pr[i][j].push(faradtsag[i][j]);
					}
					else
					{
						sum[i][j] = sum[i][j - 1] + faradtsag[i][j];
						pr[i][j] = pr[i][j - 1];
						pr[i][j].push(faradtsag[i][j]);
					}
				}
			}
		}
	}
	cout << min(f, s) << endl;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
RészfeladatÖsszpontTesztVerdiktIdőMemória
base28/50
1Elfogadva0/03ms1816 KiB
2Hibás válasz0/09ms3236 KiB
3Elfogadva2/24ms3524 KiB
4Elfogadva2/24ms3660 KiB
5Elfogadva3/34ms3864 KiB
6Elfogadva3/34ms3940 KiB
7Elfogadva2/28ms4148 KiB
8Elfogadva3/38ms4240 KiB
9Hibás válasz0/23ms3248 KiB
10Elfogadva2/23ms3328 KiB
11Elfogadva3/33ms3332 KiB
12Hibás válasz0/33ms3332 KiB
13Hibás válasz0/24ms3404 KiB
14Hibás válasz0/34ms3412 KiB
15Hibás válasz0/29ms4424 KiB
16Hibás válasz0/39ms4552 KiB
17Elfogadva2/29ms4708 KiB
18Elfogadva3/39ms4564 KiB
19Hibás válasz0/29ms4568 KiB
20Hibás válasz0/39ms4568 KiB
21Hibás válasz0/29ms4616 KiB
22Elfogadva3/39ms4576 KiB