Submission #147460


Source Code Expand

#define NDEBUG
#include <string>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cassert>

using namespace std;

const char * readLineAsCStr() {
	static char buf[65536];
	fgets(buf, sizeof(buf), stdin);
	int len = strlen(buf);
	while(buf[--len]=='\n') {
		buf[len] = '\0';
	}
	return buf;
}

int readLineAsInt() {
	return atoi(readLineAsCStr());
}

const string & readCell(const char * delim = NULL) {
	static vector<string> vec;
	static size_t count = 0;
	if(delim!=NULL) {
		vec.clear();
		const char * p = readLineAsCStr();
		int len = strlen(delim);
		while(true) {
			const char * nx = strstr(p, delim);
			if(nx==NULL) {
				vec.push_back(p);
				break;
			}
			vec.push_back(string(p, nx));
			p = nx + len;
		}
		count = 0;
	}
	assert(count<vec.size());
	return vec[count++];
}

const char * readCellAsCStr(const char * delim = NULL) {
	return readCell(delim).c_str();
}

int readCellAsInt(const char * delim = NULL) {
	return atoi(readCellAsCStr(delim));
}

int main() {
	int N = readLineAsInt();
	int D[50][50];
	for(int i=0; i<N; ++i) {
		for(int j=0; j<N; ++j) {
			D[i][j] = readCellAsInt(j==0 ? " " : NULL);
		}
	}
	int sum[51][51] = {{0}};
	for(int i=0; i<N; ++i) {
		for(int j=0; j<N; ++j) {
			sum[i+1][j+1] = sum[i+1][j]+sum[i][j+1]-sum[i][j]+D[i][j];
		}
	}

	int result[2501] = {0};
	for(int i=0; i<N; ++i) {
		for(int j=0; j<N; ++j) {
			for(int w=1; w<=N-i; ++w) {
				for(int h=1; h<=N-j; ++h) {
					int P = w*h;
					int ret = sum[i+w][j+h]-sum[i][j+h]-sum[i+w][j]+sum[i][j];
					result[P] = max(result[P], ret);
				}
			}
		}
	}
	int Q = readLineAsInt();
	for(int k=0; k<Q; ++k) {
		int P = readLineAsInt();
		int ret = 0;
		for(int l=0; l<=P; ++l) {
			ret = max(ret, result[l]);
		}
		printf("%d\n", ret);
	}

	return 0;
}

Submission Info

Submission Time
Task D - おいしいたこ焼きの焼き方
User colun
Language C++11 (GCC 4.8.1)
Score 100
Code Size 1882 Byte
Status AC
Exec Time 32 ms
Memory 932 KB

Compile Error

./Main.cpp: In function ‘const char* readLineAsCStr()’:
./Main.cpp:13:32: warning: ignoring return value of ‘char* fgets(char*, int, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
  fgets(buf, sizeof(buf), stdin);
                                ^

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 24 ms 924 KB
rand1.txt AC 23 ms 932 KB
rand2.txt AC 26 ms 932 KB
rand3.txt AC 22 ms 924 KB
rand4.txt AC 20 ms 928 KB
rand_max0.txt AC 31 ms 928 KB
rand_max1.txt AC 30 ms 920 KB
rand_max2.txt AC 32 ms 920 KB
rand_max3.txt AC 31 ms 804 KB
rand_max4.txt AC 30 ms 928 KB
s1.txt AC 22 ms 928 KB
s2.txt AC 21 ms 928 KB
sub0.txt AC 20 ms 808 KB
sub1.txt AC 21 ms 932 KB
sub2.txt AC 21 ms 932 KB
sub_rand_max0.txt AC 20 ms 792 KB
sub_rand_max1.txt AC 20 ms 932 KB
sub_rand_max2.txt AC 22 ms 728 KB
sub_rand_max3.txt AC 21 ms 924 KB
sub_rand_min0.txt AC 19 ms 800 KB