Submission #19261204


Source Code Expand

Copy
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	static long mod = 1000000007;

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();

		int[] a = new int[n], b = new int[n], c = new int[n], w = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			c[i] = sc.nextInt();
			w[i] = sc.nextInt();
		}

		int[] x = new int[m], y = new int[m], z = new int[m];
		for(int i = 0; i < m; i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
			z[i] = sc.nextInt();
		}

		int[][][] dp = new int[101][101][101];
		for(int i = 0; i < n; i++) {
			dp[a[i]][b[i]][c[i]] = Math.max(dp[a[i]][b[i]][c[i]],w[i]);
		}

		for(int i = 0; i < 101; i++) {
			for(int j = 0; j < 101; j++) {
				for(int k = 0; k < 101; k++) {
					int tmp = dp[i][j][k];

					if(i != 0) {
						tmp = Math.max(tmp, dp[i-1][j][k]);
					}
					if(j != 0) {
						tmp = Math.max(tmp, dp[i][j-1][k]);
					}
					if(k != 0) {
						tmp = Math.max(tmp, dp[i][j][k-1]);
					}

					dp[i][j][k] = tmp;
				}
			}
		}

		for(int i = 0; i < m; i++) {
			System.out.println(dp[x[i]][y[i]][z[i]]);
		}


	}

}



class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in2) {
		// TODO 自動生成されたコンストラクター・スタブ
	}
	private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Submission Info

Submission Time
Task C - Optimal Recommendations
User kiruto398
Language Java (OpenJDK 11.0.6)
Score 100
Code Size 3587 Byte
Status AC
Exec Time 493 ms
Memory 50544 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 24
Set Name Test Cases
All 10-random-00.txt, 10-random-01.txt, 10-random-02.txt, 10-random-03.txt, 10-random-04.txt, 20-absW-00.txt, 20-absW-01.txt, 20-absW-02.txt, 20-absW-03.txt, 20-absW-04.txt, 30-balance-00.txt, 30-balance-01.txt, 30-balance-02.txt, 30-balance-03.txt, 30-balance-04.txt, 40-limit_dim-00.txt, 40-limit_dim-01.txt, 40-limit_dim-02.txt, 40-limit_dim-03.txt, 40-limit_dim-04.txt, 40-limit_dim-05.txt, 40-limit_dim-06.txt, Corner1.txt, Sample1.txt
Case Name Status Exec Time Memory
10-random-00.txt AC 453 ms 48196 KB
10-random-01.txt AC 110 ms 37928 KB
10-random-02.txt AC 372 ms 44364 KB
10-random-03.txt AC 397 ms 46492 KB
10-random-04.txt AC 207 ms 40088 KB
20-absW-00.txt AC 432 ms 48320 KB
20-absW-01.txt AC 107 ms 37716 KB
20-absW-02.txt AC 284 ms 42468 KB
20-absW-03.txt AC 398 ms 46888 KB
20-absW-04.txt AC 277 ms 41592 KB
30-balance-00.txt AC 443 ms 48832 KB
30-balance-01.txt AC 119 ms 37868 KB
30-balance-02.txt AC 288 ms 41520 KB
30-balance-03.txt AC 286 ms 42904 KB
30-balance-04.txt AC 392 ms 46112 KB
40-limit_dim-00.txt AC 441 ms 48804 KB
40-limit_dim-01.txt AC 442 ms 48304 KB
40-limit_dim-02.txt AC 449 ms 48184 KB
40-limit_dim-03.txt AC 493 ms 50544 KB
40-limit_dim-04.txt AC 462 ms 50352 KB
40-limit_dim-05.txt AC 440 ms 48656 KB
40-limit_dim-06.txt AC 449 ms 48308 KB
Corner1.txt AC 102 ms 37736 KB
Sample1.txt AC 110 ms 37952 KB