結果
| 問題 | 
                            No.335 門松宝くじ
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2016-07-28 21:21:23 | 
| 言語 | Java  (openjdk 23)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 3,607 bytes | 
| コンパイル時間 | 3,853 ms | 
| コンパイル使用メモリ | 78,684 KB | 
| 実行使用メモリ | 57,980 KB | 
| 最終ジャッジ日時 | 2024-11-06 18:14:24 | 
| 合計ジャッジ時間 | 7,292 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 9 WA * 1 | 
ソースコード
import java.io.*;
import java.util.*;
public class Main_yukicoder335 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Printer pr = new Printer(System.out);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int maxe = 0;
        int maxei = 0;
        for (int mm = 0; mm < m; mm++) {
        	int[] e = new int[n];
        	for (int i = 0; i < n; i++) {
        		e[i] = sc.nextInt();
        	}
        	int[][] max = new int[n][n];
        	for (int i = 0; i < n; i++) {
        		max[i][i] = e[i];
        		for (int j = i + 1; j < n; j++) {
        			max[i][j] = Math.max(max[i][j - 1], e[j]);
        		}
        	}
        	int[][] maxi = new int[n][n];
        	for (int i = 0; i < n; i++) {
        		for (int j = i + 1; j < n; j++) {
        			if (e[j] < e[i]) {
        				maxi[i][j] = Math.max(maxi[i][j - 1], e[j]);
        			}
        		}
        	}
        	int[][] maxj = new int[n][n];
        	for (int i = n - 1; i >= 0; i--) {
        		for (int j = i - 1; j >= 0; j--) {
        			if (e[j] < e[i]) {
        				maxj[i][j] = Math.max(maxj[i][j + 1], e[j]);
        			}
        		}
        	}
        	int sum = 0;
        	for (int i = 0; i < n; i++) {
        		for (int j = i + 1; j < n; j++) {
        			int tmp = 0;
        			if (e[j] > e[i]) {
        				if (i > 0 && max[0][i - 1] > e[i]) {
        					tmp = Math.max(tmp, max[0][i - 1]);
        				}
        				if (j > i + 1 && max[i + 1][j - 1] > e[j]) {
        					tmp = Math.max(tmp, max[i + 1][j - 1]);
        				}
        				if (j > i + 1) {
        					tmp = Math.max(tmp, maxi[i][j]);
        				}
        				if (j < n - 1) {
        					tmp = Math.max(tmp, maxi[j][n - 1]);
        				}
        			} else {
        				if (i > 0) {
        					tmp = Math.max(tmp, maxj[0][i]);
        				}
        				if (j > i + 1 && max[i + 1][j - 1] > e[i]) {
        					tmp = Math.max(tmp, max[i + 1][j - 1]);
        				}
        				if (j > i + 1) {
        					tmp = Math.max(tmp, maxj[i][j]);
        				}
        				if (j < n - 1 && max[j + 1][n - 1] > e[j]) {
        					tmp = Math.max(tmp, max[j + 1][n - 1]);
        				}
        			}
        			if (tmp > 0) {
        				sum += e[i] + e[j] + tmp;
        			}
        		}
        	}
        	if (sum > maxe) {
        		maxe = sum;
        		maxei = mm;
        	}
        }
        pr.println(maxei);
        pr.close();
        sc.close();
    }
	@SuppressWarnings("unused")
	private static class Scanner {
		BufferedReader br;
		Iterator<String> it;
		Scanner (InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}
		String next() throws RuntimeException  {
			try {
				if (it == null || !it.hasNext()) {
//					it = Arrays.asList(br.readLine().split(" ")).iterator();
					it = Arrays.asList(br.readLine().split("\\p{javaWhitespace}+")).iterator();
				}
				return it.next();
			} catch (IOException e) {
				throw new IllegalStateException();
			}
		}
		int nextInt() throws RuntimeException {
			return Integer.parseInt(next());
		}
		long nextLong() throws RuntimeException {
			return Long.parseLong(next());
		}
		float nextFloat() throws RuntimeException {
			return Float.parseFloat(next());
		}
		double nextDouble() throws RuntimeException {
			return Double.parseDouble(next());
		}
		void close() {
			try {
				br.close();
			} catch (IOException e) {
//				throw new IllegalStateException();
			}
		}
	}
	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}