Submission #149038


Source Code Expand

#include <iostream>
#include <vector>

using namespace std;

void solve()
{
	int N;
	cin >> N;
	vector< vector<int> > D(N + 1, vector<int>(N + 1));
	for(int i = 1; i <= N; ++i)
	{
		for(int j = 1; j <= N; ++j)
		{
			cin >> D[i][j];
		}
	}
	
	for(int i = 0; i <= N; ++i)
	{
		for(int j = 1; j <= N; ++j)
		{
			D[i][j] += D[i][j - 1];
		}
	}
	for(int j = 0; j <= N; ++j)
	{
		for(int i = 1; i <= N; ++i)
		{
			D[i][j] += D[i - 1][j];
		}
	}

	vector<int> res(N * N + 1);
	for(int u = 1; u <= N; ++u)
	{
		for(int b = 0; b < u; ++b)
		{
			for(int r = 1; r <= N; ++r)
			{
				for(int l = 0; l < r; ++l)
				{
					res[(r - l) * (u - b)] = max(res[(r - l) * (u - b)], D[u][r] - D[b][r] - D[u][l] + D[b][l]);
				}
			}
		}
	}
	
	int size = N * N;
	for(int i = 1; i <= size; ++i)
	{
		res[i] = max(res[i], res[i - 1]);
	}
	int Q;
	cin >> Q;
	for(int i = 0; i < Q; ++i)
	{
		int p;
		cin >> p;
		cout << res[p] << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Submission Info

Submission Time
Task D - おいしいたこ焼きの焼き方
User smon
Language C++ (G++ 4.6.4)
Score 100
Code Size 1027 Byte
Status AC
Exec Time 40 ms
Memory 932 KB

Judge Result

Set Name Subtask1 Subtask2
Score / Max Score 50 / 50 50 / 50
Status
AC × 18
AC × 20
Set Name Test Cases
Subtask1 sub0.txt, sub1.txt, sub2.txt, sub_rand_max0.txt, sub_rand_max1.txt, sub_rand_max2.txt, sub_rand_max3.txt, sub_rand_min0.txt, s1.txt, s2.txt, sub0.txt, sub1.txt, sub2.txt, sub_rand_max0.txt, sub_rand_max1.txt, sub_rand_max2.txt, sub_rand_max3.txt, sub_rand_min0.txt
Subtask2 rand0.txt, rand1.txt, rand2.txt, rand3.txt, rand4.txt, rand_max0.txt, rand_max1.txt, rand_max2.txt, rand_max3.txt, rand_max4.txt, s1.txt, s2.txt, sub0.txt, sub1.txt, sub2.txt, sub_rand_max0.txt, sub_rand_max1.txt, sub_rand_max2.txt, sub_rand_max3.txt, sub_rand_min0.txt
Case Name Status Exec Time Memory
rand0.txt AC 26 ms 932 KB
rand1.txt AC 27 ms 800 KB
rand2.txt AC 32 ms 804 KB
rand3.txt AC 24 ms 928 KB
rand4.txt AC 22 ms 924 KB
rand_max0.txt AC 38 ms 800 KB
rand_max1.txt AC 39 ms 800 KB
rand_max2.txt AC 38 ms 796 KB
rand_max3.txt AC 39 ms 932 KB
rand_max4.txt AC 40 ms 928 KB
s1.txt AC 21 ms 932 KB
s2.txt AC 24 ms 756 KB
sub0.txt AC 21 ms 764 KB
sub1.txt AC 21 ms 928 KB
sub2.txt AC 21 ms 804 KB
sub_rand_max0.txt AC 21 ms 804 KB
sub_rand_max1.txt AC 21 ms 676 KB
sub_rand_max2.txt AC 21 ms 924 KB
sub_rand_max3.txt AC 21 ms 812 KB
sub_rand_min0.txt AC 21 ms 800 KB