結果

問題 No.941 商とあまり
ユーザー uwiuwi
提出日時 2019-12-04 03:43:56
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 5,914 bytes
コンパイル時間 6,340 ms
コンパイル使用メモリ 87,908 KB
実行使用メモリ 235,036 KB
最終ジャッジ日時 2024-05-06 12:43:47
合計ジャッジ時間 34,930 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 324 ms
66,084 KB
testcase_01 AC 195 ms
45,264 KB
testcase_02 AC 194 ms
44,684 KB
testcase_03 AC 194 ms
45,560 KB
testcase_04 AC 182 ms
44,112 KB
testcase_05 AC 184 ms
44,272 KB
testcase_06 AC 177 ms
44,292 KB
testcase_07 AC 202 ms
48,328 KB
testcase_08 AC 214 ms
48,668 KB
testcase_09 AC 196 ms
48,084 KB
testcase_10 AC 218 ms
52,100 KB
testcase_11 AC 236 ms
50,176 KB
testcase_12 AC 205 ms
46,852 KB
testcase_13 AC 272 ms
56,876 KB
testcase_14 AC 249 ms
50,236 KB
testcase_15 AC 280 ms
59,376 KB
testcase_16 AC 318 ms
63,440 KB
testcase_17 AC 423 ms
65,412 KB
testcase_18 AC 779 ms
88,812 KB
testcase_19 TLE -
testcase_20 AC 185 ms
44,140 KB
testcase_21 AC 193 ms
44,180 KB
testcase_22 AC 183 ms
44,124 KB
testcase_23 AC 46 ms
36,860 KB
testcase_24 AC 48 ms
37,132 KB
testcase_25 AC 49 ms
36,880 KB
testcase_26 AC 265 ms
52,148 KB
testcase_27 AC 283 ms
57,604 KB
testcase_28 AC 254 ms
49,672 KB
testcase_29 AC 388 ms
66,272 KB
testcase_30 AC 411 ms
66,328 KB
testcase_31 AC 256 ms
49,404 KB
testcase_32 AC 209 ms
46,896 KB
testcase_33 AC 192 ms
44,100 KB
testcase_34 AC 784 ms
89,140 KB
testcase_35 AC 689 ms
87,128 KB
testcase_36 AC 222 ms
48,180 KB
testcase_37 AC 206 ms
48,344 KB
testcase_38 AC 230 ms
48,320 KB
testcase_39 AC 249 ms
48,080 KB
testcase_40 AC 175 ms
44,128 KB
testcase_41 AC 179 ms
44,152 KB
testcase_42 AC 193 ms
44,092 KB
testcase_43 AC 230 ms
48,088 KB
testcase_44 AC 214 ms
48,120 KB
testcase_45 AC 1,685 ms
126,600 KB
testcase_46 AC 709 ms
88,452 KB
testcase_47 AC 249 ms
49,240 KB
testcase_48 AC 184 ms
44,440 KB
testcase_49 AC 285 ms
56,104 KB
testcase_50 AC 242 ms
50,060 KB
testcase_51 AC 252 ms
50,980 KB
testcase_52 AC 232 ms
49,288 KB
testcase_53 AC 219 ms
50,328 KB
testcase_54 AC 1,890 ms
149,060 KB
testcase_55 AC 1,863 ms
148,892 KB
testcase_56 AC 1,814 ms
148,892 KB
testcase_57 TLE -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
testcase_79 -- -
testcase_80 -- -
testcase_81 -- -
testcase_82 -- -
testcase_83 -- -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
testcase_87 -- -
testcase_88 -- -
testcase_89 -- -
testcase_90 -- -
testcase_91 -- -
testcase_92 -- -
testcase_93 -- -
testcase_94 -- -
testcase_95 -- -
testcase_96 -- -
testcase_97 -- -
testcase_98 -- -
testcase_99 -- -
testcase_100 -- -
testcase_101 -- -
testcase_102 -- -
testcase_103 -- -
testcase_104 -- -
testcase_105 -- -
testcase_106 -- -
testcase_107 -- -
testcase_108 -- -
testcase_109 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Adv19D4_3 {
	InputStream is;
	PrintWriter out;
	String INPUT = "";
//	String INPUT = "4 500000 65 66 67 68";
//	String INPUT = "6 500000 1 2 3 4 5 6";
//	String INPUT = "4 500000 3 4 5 6";
//	String INPUT = "18 500000 1 1 1 1 1  1 1 1 1 1  1 1 1 1 1  1 1 1";
//	String INPUT = "6 500000 5 7 11 13 17 23";
	
	int max =0;
	
	void solve()
	{
		int n = ni(), X = ni();
		int[] a = na(n);
		double u = 1;
		for(int v : a) {
			u *= v+1;
			if(u-1 > X) {
				for(int i = 0;i < X;i++) {
					out.print(0);
				}
				out.println();
				return;
			}
		}
		
		Arrays.sort(a);
		int[][] f = uniqcount(a);
		int[] fi = new int[f.length];
		for(int i = 0;i < f.length;i++)fi[i] = f[i][1] + 1;
		Denom de = new Denom(fi);
		
		boolean[][] dp = new boolean[de.all()][X+1];
		for(int i = 0;i < de.all();i++) {
			for(int j = 0;j < f.length;j++) {
				if(de.in(i, j, 1)) {
					int ni = de.add(i, j, 1);
					if(i == 0) {
						dp[ni][f[j][0]] = true;
					}else {
//						tr(i, j, ni);
						int l = f[j][0];
//						int ct = 0;
						long h = 0;
						for(int k = 1;(long)k*(l+1)+l <= X;k++) {
							if(dp[i][k]) {
//								tr(k);
								for(int m = k*(l+1)+l;m <= X;m+=k) {
//									ct++;
									dp[ni][m] = true;
								}
								if(k%l < 64) {
									if(h<<~(k%l)<0) {
										continue;
									}
									h |= 1L<<(k%l);
								}
								for(int m = k*(l+1)+l;m <= X;m+=l) {
//									ct++;
									dp[ni][m] = true;
								}
							}
						}
//						tr(i, j, ni, ct);
					}
				}
			}
		}
		for(int i = 1;i <= X;i++) {
			out.print(dp[de.all()-1][i] ? 1 : 0);
		}
		out.println();
	}
	
	public static int[] getind(int[][] a, int ind) {
		int[] b = new int[a.length];
		for(int i = 0;i < a.length;i++)b[i] = a[i][ind];
		return b;
	}

	
	public static class Denom
	{
		int[] a;
		int[] ia;
		
		Denom(int... ia)
		{
			this.ia = ia;
			int n = ia.length;
			a = new int[n+1];
			a[0] = 1;
			for(int i = 0;i < n;i++){
				a[i+1] = a[i] * ia[i];
			}
		}
		
		int[] dec(int code)
		{
			int[] ret = new int[a.length-1];
			for(int i = 0;i < a.length-1;i++) {
				ret[i] = code % a[i+1] / a[i];
			}
			return ret;
		}
		
		int ind(int... x)
		{
			assert x.length == ia.length;
			int ret = 0;
			for(int i = 0;i < x.length;i++){
				ret += x[i] * a[i];
			}
			return ret;
		}
		
		boolean in(int code, int which, int plus)
		{
			int v = v(code, which);
			return 0 <= v + plus && v + plus < ia[which];
		}
		
		int v(int code, int which)
		{
			return code / a[which] % ia[which];
		}
		
		int add(int code, int which, int plus)
		{
			return code + a[which] * plus;
		}
		
		int update(int code, int which, int val)
		{
			return code + (-code / a[which] % ia[which] + val) * a[which];
		}
		
		int all() { return a[a.length-1]; }
	}

	
	public static int[][] uniqcount(int[] a)
	{
		int n = a.length;
		int p = 0;
		int[][] b = new int[n][];
		for(int i = 0;i < n;i++){
			if(i == 0 || a[i] != a[i-1])b[p++] = new int[]{a[i], 0};
			b[p-1][1]++;
		}
		return Arrays.copyOf(b, p);
	}

	
	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 Adv19D4_3().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)); }
}
0