Submission #19261160


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]] = 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 0
Code Size 3556 Byte
Status WA
Exec Time 481 ms
Memory 50960 KB

Judge Result

Set Name All
Score / Max Score 0 / 100
Status
AC × 10
WA × 14
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 WA 448 ms 48480 KB
10-random-01.txt AC 107 ms 37644 KB
10-random-02.txt AC 347 ms 45060 KB
10-random-03.txt WA 396 ms 46252 KB
10-random-04.txt WA 229 ms 39936 KB
20-absW-00.txt AC 444 ms 48204 KB
20-absW-01.txt AC 110 ms 37816 KB
20-absW-02.txt AC 299 ms 42716 KB
20-absW-03.txt AC 397 ms 46852 KB
20-absW-04.txt AC 280 ms 41932 KB
30-balance-00.txt WA 461 ms 48340 KB
30-balance-01.txt AC 105 ms 37792 KB
30-balance-02.txt AC 305 ms 42784 KB
30-balance-03.txt WA 305 ms 41992 KB
30-balance-04.txt WA 396 ms 46312 KB
40-limit_dim-00.txt WA 479 ms 50104 KB
40-limit_dim-01.txt WA 438 ms 48376 KB
40-limit_dim-02.txt WA 481 ms 50960 KB
40-limit_dim-03.txt WA 455 ms 48512 KB
40-limit_dim-04.txt WA 441 ms 48092 KB
40-limit_dim-05.txt WA 434 ms 47912 KB
40-limit_dim-06.txt WA 442 ms 48452 KB
Corner1.txt WA 110 ms 37708 KB
Sample1.txt AC 110 ms 37800 KB