94512024-02-21 21:07:22ananászDinamitcpp17Wrong answer 28/509ms4364 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)
						{
							
							//yf = xf;
						}
						else
						{
							//yf = xf + 1;
							f--;
						}
						xf = xf / 2;
						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
SubtaskSumTestVerdictTimeMemory
base28/50
1Accepted0/03ms1712 KiB
2Wrong answer0/09ms3084 KiB
3Accepted2/24ms3296 KiB
4Accepted2/24ms3508 KiB
5Accepted3/34ms3708 KiB
6Accepted3/34ms3664 KiB
7Accepted2/27ms3672 KiB
8Accepted3/38ms3924 KiB
9Wrong answer0/23ms2872 KiB
10Accepted2/23ms2892 KiB
11Accepted3/33ms2896 KiB
12Wrong answer0/33ms2896 KiB
13Wrong answer0/24ms2864 KiB
14Wrong answer0/34ms3124 KiB
15Wrong answer0/29ms4068 KiB
16Wrong answer0/39ms4072 KiB
17Accepted2/29ms4068 KiB
18Accepted3/39ms4116 KiB
19Wrong answer0/29ms4076 KiB
20Wrong answer0/39ms4364 KiB
21Wrong answer0/29ms4280 KiB
22Accepted3/39ms4288 KiB