Submission #801120

# Submission time Handle Problem Language Result Execution time Memory
801120 2023-08-02T04:39:44 Z Tunglam07 Zemljište (COCI22_zemljiste) C++17
0 / 70
2 ms 4180 KB
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); 
    cout.tie(0);
	long long n, m, a, b, c[501][501], price[501][501];
    cin >> n >> m >> a >> b;
    for(int i = 1; i <= n; i++)
	{
        for(int j = 1; j <= m; j++)
		{
            cin >> c[i][j];
        }
    }    
 
    for(int i = 1; i <= n; i++)
	{
        for(int j = 1; j <= m; j++)
		{
            price[i][j] = price[i - 1][j] + price[i][j - 1] - price[i - 1][j - 1] + c[i][j]; 
        }
    }
 
    long long ans = INT_MAX;
    if(a > b) 
	{
		swap(a, b);
	}
 
    for(int i = 1; i <= n; i++)
	{
         for(int j = i; j <= n; j++)
		 {
            long long p = 0;
 
            for(int k = 1; k <= m; k++)
			{
                long long val = price[j][k]-price[i-1][k]-price[j][0]+price[i-1][0];
                long long val2 = price[j][p] - price[i-1][p] - price[j][0] + price[i-1][0];
				while(p < k && val - val2 >= a) 
				{
					p++;
				}
                
                if(p < k) 
				{
					ans = min(ans, abs(val - val2 - a) + abs(val - val2 - b));
				}
                if(p >= 1) 
				{
					long long val3 = price[j][p-1] - price[i-1][p-1] - price[j][0] + price[i-1][0];
					ans = min(ans, abs(val - val3 - a) + abs(val - val3 - b));
				}
            }
         }
    }
    cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 2 ms 4180 KB Output is correct
3 Correct 2 ms 4180 KB Output is correct
4 Correct 2 ms 4180 KB Output is correct
5 Incorrect 2 ms 4180 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 2 ms 4180 KB Output is correct
3 Correct 2 ms 4180 KB Output is correct
4 Correct 2 ms 4180 KB Output is correct
5 Incorrect 2 ms 4180 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 2 ms 4180 KB Output is correct
3 Correct 2 ms 4180 KB Output is correct
4 Correct 2 ms 4180 KB Output is correct
5 Incorrect 2 ms 4180 KB Output isn't correct
6 Halted 0 ms 0 KB -