Submission #60296


Source Code Expand

import java.util.Arrays;

public class Main {

	int n, m, res;
	char[][] cake;
	
	boolean check(int i, int j){
		return 0<=i&&i<n&&0<=j&&j<m&&cake[i][j]!='X';
	}
	
	int f(int pi, int pj, int x){
		if(cake[pi][pj]=='X')return -1;
		int cnt = 0, t = 1;
		boolean con = true;
		if(x==0){
			cnt = cake[pi][pj]-'0';
			pi--;
			t++;
			while(con){
				int c = 0;
				for(int d=0;d<t;d++){
					int ni = pi+d, nj = pj+d;
					if(!check(ni, nj))return cnt;
					c+=cake[ni][nj]-'0';
				}
				cnt+=c;
				pi--;
				t++;
			}
		}
		else if(x==1){
			cnt = cake[pi][pj]-'0';
			pi--;
			t++;
			while(con){
				int c = 0;
				for(int d=0;d<t;d++){
					int ni = pi+d, nj = pj-d;
					if(!check(ni, nj))return cnt;
					c+=cake[ni][nj]-'0';
				}
				cnt+=c;
				pi--;
				t++;
			}
		}
		else if(x==2){
			cnt = cake[pi][pj]-'0';
			pi++;
			t++;
			while(con){
				int c = 0;
				for(int d=0;d<t;d++){
					int ni = pi-d, nj = pj+d;
					if(!check(ni, nj))return cnt;
					c+=cake[ni][nj]-'0';
				}
				cnt+=c;
				pi++;
				t++;
			}
		}
		else{
			cnt = cake[pi][pj]-'0';
			pi++;
			t++;
			while(con){
				int c = 0;
				for(int d=0;d<t;d++){
					int ni = pi-d, nj = pj-d;
					if(!check(ni, nj))return cnt;
					c+=cake[ni][nj]-'0';
				}
				cnt+=c;
				pi++;
				t++;
			}
		}
		return 0;
	}
	
	void run() {
		Scanner sc = new Scanner();
		n = sc.nextInt(); m = sc.nextInt();
		cake = new char[n][];
		for(int i=0;i<n;i++)cake[i]=sc.next().toCharArray();
		res = 0;
		for(int i=0;i<n;i++)for(int j=0;j<m;j++)for(int x=0;x<4;x++)res=Math.max(res, f(i, j, x));
		System.out.println(res);
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	 class Scanner {
			int nextInt() {
				try {
					int c = System.in.read();
					while (c != '-' && (c < '0' || '9' < c))
						c = System.in.read();
					if (c == '-') return -nextInt();
					int res = 0;
					do {
						res *= 10;
						res += c - '0';
						c = System.in.read();
					} while ('0' <= c && c <= '9');
					return res;
				} catch (Exception e) {
					return -1;
				}
			}
			long nextLong() {
				try {
					int c = System.in.read();
					while (c != '-' && (c < '0' || '9' < c))
						c = System.in.read();
					if (c == '-') return -nextLong();
					long res = 0;
					do {
						res *= 10;
						res += c - '0';
						c = System.in.read();
					} while ('0' <= c && c <= '9');
					return res;
				} catch (Exception e) {
					return -1;
				}
			}
			double nextDouble() {
				return Double.parseDouble(next());
			}
			String next() {
				try {
					StringBuilder res = new StringBuilder("");
					int c = System.in.read();
					while (Character.isWhitespace(c))
						c = System.in.read();
					do {
						res.append((char) c);
					} while (!Character.isWhitespace(c = System.in.read()));
					return res.toString();
				} catch (Exception e) {
					return null;
				}
			}
			String nextLine(){
				try{
					StringBuilder res =new StringBuilder("");
					int c = System.in.read();
					while (c=='\r' || c=='\n')
						c = System.in.read();
					do {
						res.append((char) c);
						c = System.in.read();
					} while (c!='\r' && c!='\n');
					return res.toString();
				}catch (Exception e) {
					return null;
				}
			}
		}
	
	public static void main(String... args) {
		new Main().run();
	}
}

Submission Info

Submission Time
Task C - 至高のケーキ
User nanikaka
Language Java (OpenJDK 1.7.0)
Score 75
Code Size 3469 Byte
Status AC
Exec Time 452 ms
Memory 21148 KB

Judge Result

Set Name All
Score / Max Score 75 / 75
Status
AC × 55
Set Name Test Cases
All case_000.txt, case_001.txt, case_002.txt, case_003.txt, case_004.txt, case_005.txt, case_006.txt, case_007.txt, case_008.txt, case_009.txt, case_010.txt, case_011.txt, case_012.txt, case_013.txt, case_014.txt, case_015.txt, case_016.txt, case_017.txt, case_018.txt, case_019.txt, case_020.txt, case_021.txt, case_022.txt, case_023.txt, case_024.txt, case_025.txt, case_026.txt, case_027.txt, case_028.txt, case_029.txt, case_030.txt, case_031.txt, case_032.txt, case_033.txt, case_034.txt, case_035.txt, case_036.txt, case_037.txt, case_038.txt, case_039.txt, case_040.txt, case_041.txt, case_042.txt, case_043.txt, case_044.txt, case_045.txt, case_046.txt, case_047.txt, case_048.txt, case_049.txt, case_050.txt, case_051.txt, case_052.txt, case_053.txt, case_054.txt
Case Name Status Exec Time Memory
case_000.txt AC 379 ms 18400 KB
case_001.txt AC 376 ms 18356 KB
case_002.txt AC 391 ms 18484 KB
case_003.txt AC 396 ms 18400 KB
case_004.txt AC 386 ms 18480 KB
case_005.txt AC 384 ms 18484 KB
case_006.txt AC 401 ms 18356 KB
case_007.txt AC 407 ms 18348 KB
case_008.txt AC 376 ms 18480 KB
case_009.txt AC 399 ms 18520 KB
case_010.txt AC 420 ms 21148 KB
case_011.txt AC 412 ms 21100 KB
case_012.txt AC 381 ms 18384 KB
case_013.txt AC 391 ms 18480 KB
case_014.txt AC 382 ms 18412 KB
case_015.txt AC 403 ms 19252 KB
case_016.txt AC 374 ms 18376 KB
case_017.txt AC 417 ms 18392 KB
case_018.txt AC 373 ms 18392 KB
case_019.txt AC 403 ms 18416 KB
case_020.txt AC 373 ms 18404 KB
case_021.txt AC 403 ms 18488 KB
case_022.txt AC 374 ms 18472 KB
case_023.txt AC 402 ms 18464 KB
case_024.txt AC 376 ms 18476 KB
case_025.txt AC 373 ms 18356 KB
case_026.txt AC 452 ms 18484 KB
case_027.txt AC 398 ms 18356 KB
case_028.txt AC 416 ms 18480 KB
case_029.txt AC 402 ms 18484 KB
case_030.txt AC 404 ms 18464 KB
case_031.txt AC 408 ms 18352 KB
case_032.txt AC 431 ms 18408 KB
case_033.txt AC 397 ms 18472 KB
case_034.txt AC 433 ms 18516 KB
case_035.txt AC 404 ms 18468 KB
case_036.txt AC 425 ms 18476 KB
case_037.txt AC 435 ms 18532 KB
case_038.txt AC 425 ms 18464 KB
case_039.txt AC 400 ms 18444 KB
case_040.txt AC 398 ms 18484 KB
case_041.txt AC 433 ms 18488 KB
case_042.txt AC 401 ms 18488 KB
case_043.txt AC 403 ms 18484 KB
case_044.txt AC 385 ms 18400 KB
case_045.txt AC 388 ms 18480 KB
case_046.txt AC 411 ms 19636 KB
case_047.txt AC 395 ms 18460 KB
case_048.txt AC 391 ms 18520 KB
case_049.txt AC 398 ms 18484 KB
case_050.txt AC 423 ms 18472 KB
case_051.txt AC 450 ms 20912 KB
case_052.txt AC 417 ms 18480 KB
case_053.txt AC 411 ms 18340 KB
case_054.txt AC 424 ms 18488 KB