Submission #2557882


Source Code Expand

#include <stdio.h>
#include <stdlib.h>
 
int main() {
	int n, q;
	int total_oishisa = 0;
	int max_oishisa = 0;
	int i, j, k, l;
	int tate, yoko, t_side1, t_side2, cnt;
	int side1[1250], side2[1250];
	int *oishisa, *staff_power;
 
	scanf("%d", &n);
	oishisa = (int *)malloc(sizeof(int) * n * n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			scanf("%d", &oishisa[i * n + j]);
		}
	}
 
	scanf("%d", &q);
	staff_power = (int *)malloc(sizeof(int) * q);
	for (i = 0; i < q; i++) {
		scanf("%d", &staff_power[i]);
	}
 
	/* 焼ける範囲とおいしさの計算 */
	for (i = 0; i < q; i++) {
		/* 焼ける範囲たてよこの組み合わせ */
		cnt = 0;
		t_side1 = n;
		t_side2 = 0;
		while (t_side1 > 0) {
			if (staff_power[i] / t_side1 > t_side2) {
					t_side2 = staff_power[i] / t_side1;
					if (t_side2 > n) {
						t_side2 = n;
					}
					if (t_side1 >= t_side2) {
						side1[cnt] = t_side1;
						side2[cnt++] = t_side2;
					} else {
						break;
					}
			}
			t_side1--;
		}
		/* 範囲内のおいしさの合計を計算 */
		for (j = 0; j < cnt; j++) {
			t_side1 = side1[j];
			t_side2 = side2[j];
 
			while (1) {
				/* 列をずらす*/
				for (tate = 0;  (t_side1 + tate) <= n; tate++) {
					/* 行をずらす*/
					for (yoko = 0; (t_side2 + yoko) <= n; yoko++) {
						for (k = 0; k < t_side1; k++) {
							for (l = 0; l < t_side2; l++) {
								total_oishisa += oishisa[(k + tate) * n + l + yoko];
							}
						}
						if (total_oishisa > max_oishisa) {
								max_oishisa = total_oishisa;
						}
						total_oishisa = 0;
					}
				}
				/* たてとよこの長さ入れ替え*/
				if (t_side1 > t_side2) {
					t_side1 = side2[j];
					t_side2 = side1[j];
				} else {
					break;
				}
			}
		}
		printf("%d\n", max_oishisa);
		max_oishisa = 0;
	}
	free(oishisa);
	free(staff_power);
 
	return 0;
}

Submission Info

Submission Time
Task D - おいしいたこ焼きの焼き方
User azusanabe
Language C (GCC 5.4.1)
Score 50
Code Size 1934 Byte
Status TLE
Exec Time 5255 ms
Memory 256 KB

Compile Error

./Main.c: In function ‘main’:
./Main.c:13:2: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ^
./Main.c:17:4: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &oishisa[i * n + j]);
    ^
./Main.c:21:2: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &q);
  ^
./Main.c:24:3: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &staff_power[i]);
   ^

Judge Result

Set Name Subtask1 Subtask2
Score / Max Score 50 / 50 0 / 50
Status
AC × 18
AC × 15
TLE × 5
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 292 ms 128 KB
rand1.txt AC 524 ms 128 KB
rand2.txt AC 1976 ms 256 KB
rand3.txt AC 47 ms 128 KB
rand4.txt AC 1 ms 128 KB
rand_max0.txt TLE 5255 ms 256 KB
rand_max1.txt TLE 5255 ms 128 KB
rand_max2.txt TLE 5255 ms 256 KB
rand_max3.txt TLE 5255 ms 128 KB
rand_max4.txt TLE 5255 ms 128 KB
s1.txt AC 1 ms 128 KB
s2.txt AC 1 ms 128 KB
sub0.txt AC 1 ms 128 KB
sub1.txt AC 1 ms 128 KB
sub2.txt AC 1 ms 128 KB
sub_rand_max0.txt AC 1 ms 128 KB
sub_rand_max1.txt AC 1 ms 128 KB
sub_rand_max2.txt AC 1 ms 128 KB
sub_rand_max3.txt AC 1 ms 128 KB
sub_rand_min0.txt AC 1 ms 128 KB