結果
問題 | No.868 ハイパー部分和問題 |
ユーザー | uwi |
提出日時 | 2019-08-17 14:44:12 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 4,098 bytes |
コンパイル時間 | 4,383 ms |
コンパイル使用メモリ | 80,972 KB |
実行使用メモリ | 44,028 KB |
最終ジャッジ日時 | 2024-09-24 19:32:01 |
合計ジャッジ時間 | 76,057 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 148 ms
40,188 KB |
testcase_01 | AC | 144 ms
39,808 KB |
testcase_02 | AC | 192 ms
41,064 KB |
testcase_03 | AC | 128 ms
39,956 KB |
testcase_04 | AC | 119 ms
39,820 KB |
testcase_05 | AC | 117 ms
40,220 KB |
testcase_06 | AC | 118 ms
39,588 KB |
testcase_07 | AC | 125 ms
40,040 KB |
testcase_08 | AC | 122 ms
39,968 KB |
testcase_09 | AC | 114 ms
39,980 KB |
testcase_10 | AC | 117 ms
39,840 KB |
testcase_11 | AC | 121 ms
39,768 KB |
testcase_12 | AC | 105 ms
39,764 KB |
testcase_13 | AC | 122 ms
40,012 KB |
testcase_14 | AC | 5,944 ms
42,504 KB |
testcase_15 | AC | 6,698 ms
42,484 KB |
testcase_16 | AC | 6,747 ms
42,300 KB |
testcase_17 | AC | 6,627 ms
42,416 KB |
testcase_18 | AC | 5,864 ms
44,028 KB |
testcase_19 | AC | 1,402 ms
42,552 KB |
testcase_20 | AC | 1,202 ms
41,660 KB |
testcase_21 | AC | 862 ms
41,592 KB |
testcase_22 | AC | 912 ms
41,976 KB |
testcase_23 | AC | 1,299 ms
41,696 KB |
testcase_24 | AC | 1,150 ms
42,248 KB |
testcase_25 | AC | 1,112 ms
42,548 KB |
testcase_26 | AC | 1,278 ms
41,908 KB |
testcase_27 | AC | 1,228 ms
42,500 KB |
testcase_28 | AC | 1,193 ms
42,368 KB |
testcase_29 | AC | 848 ms
43,144 KB |
testcase_30 | AC | 842 ms
43,416 KB |
testcase_31 | AC | 963 ms
43,712 KB |
testcase_32 | AC | 1,458 ms
43,612 KB |
testcase_33 | AC | 1,692 ms
43,244 KB |
testcase_34 | TLE | - |
testcase_35 | AC | 6,595 ms
42,456 KB |
testcase_36 | AC | 1,490 ms
43,640 KB |
testcase_37 | AC | 1,587 ms
43,356 KB |
testcase_38 | AC | 115 ms
39,676 KB |
testcase_39 | AC | 113 ms
39,536 KB |
ソースコード
package contest190816; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.math.BigInteger; import java.util.Arrays; import java.util.InputMismatchException; import java.util.Random; public class F { InputStream is; PrintWriter out; String INPUT = ""; long[] mods; void solve() { mods = new long[2]; Random gen = new Random(); for(int i = 0;i < 2;i++){ mods[i] = BigInteger.probablePrime(60, gen).longValue(); } int Z = 2; int n = ni(), K = ni(); int[] a = na(n); int D = 15005; long[][] dp = new long[Z][D]; for(int k = 0;k < Z;k++){ dp[k][0] = 1; } for(int v : a){ if(v == 0)continue; for(int k = 0;k < Z;k++){ for(int i = D-1;i >= v;i--){ dp[k][i] += dp[k][i-v]; if(dp[k][i] >= mods[k])dp[k][i] -= mods[k]; } } } for(int Q = ni();Q > 0;Q--){ int x = ni()-1, v = ni(); if(a[x] != 0){ for(int k = 0;k < Z;k++){ for(int i = a[x];i < D;i++){ dp[k][i] += mods[k] - dp[k][i-a[x]]; if(dp[k][i] >= mods[k])dp[k][i] -= mods[k]; } } } a[x] = v; if(a[x] != 0){ for(int k = 0;k < Z;k++){ for(int i = D-1;i >= a[x];i--){ dp[k][i] += dp[k][i-a[x]]; if(dp[k][i] >= mods[k])dp[k][i] -= mods[k]; } } } out.println(dp[0][K] != 0 && dp[1][K] != 0 ? 1 : 0); } } void run() throws Exception { is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes()); out = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); out.flush(); if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms"); // Thread t = new Thread(null, null, "~", Runtime.getRuntime().maxMemory()){ // @Override // public void run() { // long s = System.currentTimeMillis(); // solve(); // out.flush(); // if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms"); // } // }; // t.start(); // t.join(); } public static void main(String[] args) throws Exception { new F().run(); } private byte[] inbuf = new byte[1024]; public int lenbuf = 0, ptrbuf = 0; private int readByte() { if(lenbuf == -1)throw new InputMismatchException(); if(ptrbuf >= lenbuf){ ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if(lenbuf <= 0)return -1; } return inbuf[ptrbuf++]; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; } private double nd() { return Double.parseDouble(ns()); } private char nc() { return (char)skip(); } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while(p < n && !(isSpaceChar(b))){ buf[p++] = (char)b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private int[] na(int n) { int[] a = new int[n]; for(int i = 0;i < n;i++)a[i] = ni(); return a; } private long[] nal(int n) { long[] a = new long[n]; for(int i = 0;i < n;i++)a[i] = nl(); return a; } private char[][] nm(int n, int m) { char[][] map = new char[n][]; for(int i = 0;i < n;i++)map[i] = ns(m); return map; } private int[][] nmi(int n, int m) { int[][] map = new int[n][]; for(int i = 0;i < n;i++)map[i] = na(m); return map; } private int ni() { return (int)nl(); } private long nl() { long num = 0; int b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); } }