結果

問題 No.941 商とあまり
ユーザー uwiuwi
提出日時 2019-12-04 04:31:13
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,052 ms / 2,000 ms
コード長 6,965 bytes
コンパイル時間 6,006 ms
コンパイル使用メモリ 81,944 KB
実行使用メモリ 82,072 KB
最終ジャッジ日時 2024-05-06 15:21:08
合計ジャッジ時間 42,610 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 326 ms
48,808 KB
testcase_01 AC 189 ms
45,308 KB
testcase_02 AC 182 ms
44,296 KB
testcase_03 AC 191 ms
45,136 KB
testcase_04 AC 176 ms
43,844 KB
testcase_05 AC 179 ms
44,060 KB
testcase_06 AC 178 ms
44,584 KB
testcase_07 AC 258 ms
47,140 KB
testcase_08 AC 267 ms
47,192 KB
testcase_09 AC 216 ms
45,520 KB
testcase_10 AC 242 ms
48,008 KB
testcase_11 AC 252 ms
47,524 KB
testcase_12 AC 175 ms
44,580 KB
testcase_13 AC 308 ms
48,716 KB
testcase_14 AC 275 ms
47,892 KB
testcase_15 AC 296 ms
48,744 KB
testcase_16 AC 278 ms
49,192 KB
testcase_17 AC 301 ms
49,300 KB
testcase_18 AC 341 ms
51,304 KB
testcase_19 AC 508 ms
58,084 KB
testcase_20 AC 174 ms
44,124 KB
testcase_21 AC 176 ms
44,160 KB
testcase_22 AC 170 ms
44,384 KB
testcase_23 AC 46 ms
36,664 KB
testcase_24 AC 43 ms
36,668 KB
testcase_25 AC 44 ms
36,952 KB
testcase_26 AC 242 ms
47,948 KB
testcase_27 AC 270 ms
47,896 KB
testcase_28 AC 248 ms
47,784 KB
testcase_29 AC 308 ms
49,540 KB
testcase_30 AC 330 ms
49,156 KB
testcase_31 AC 255 ms
47,280 KB
testcase_32 AC 189 ms
44,896 KB
testcase_33 AC 179 ms
44,204 KB
testcase_34 AC 332 ms
51,492 KB
testcase_35 AC 318 ms
50,808 KB
testcase_36 AC 258 ms
47,316 KB
testcase_37 AC 249 ms
47,208 KB
testcase_38 AC 273 ms
47,280 KB
testcase_39 AC 254 ms
47,284 KB
testcase_40 AC 185 ms
44,364 KB
testcase_41 AC 184 ms
44,436 KB
testcase_42 AC 186 ms
44,472 KB
testcase_43 AC 296 ms
47,944 KB
testcase_44 AC 281 ms
47,348 KB
testcase_45 AC 435 ms
55,436 KB
testcase_46 AC 316 ms
51,412 KB
testcase_47 AC 258 ms
47,236 KB
testcase_48 AC 200 ms
44,156 KB
testcase_49 AC 305 ms
48,508 KB
testcase_50 AC 265 ms
48,220 KB
testcase_51 AC 251 ms
47,664 KB
testcase_52 AC 247 ms
47,980 KB
testcase_53 AC 252 ms
47,500 KB
testcase_54 AC 434 ms
58,080 KB
testcase_55 AC 420 ms
58,676 KB
testcase_56 AC 441 ms
58,236 KB
testcase_57 AC 1,052 ms
82,072 KB
testcase_58 AC 796 ms
69,312 KB
testcase_59 AC 268 ms
47,000 KB
testcase_60 AC 271 ms
46,836 KB
testcase_61 AC 189 ms
45,328 KB
testcase_62 AC 342 ms
47,884 KB
testcase_63 AC 305 ms
47,340 KB
testcase_64 AC 282 ms
47,004 KB
testcase_65 AC 270 ms
47,044 KB
testcase_66 AC 271 ms
47,060 KB
testcase_67 AC 326 ms
47,560 KB
testcase_68 AC 261 ms
47,576 KB
testcase_69 AC 314 ms
47,832 KB
testcase_70 AC 362 ms
48,696 KB
testcase_71 AC 302 ms
48,288 KB
testcase_72 AC 262 ms
47,560 KB
testcase_73 AC 356 ms
48,868 KB
testcase_74 AC 376 ms
49,748 KB
testcase_75 AC 331 ms
48,416 KB
testcase_76 AC 336 ms
48,232 KB
testcase_77 AC 295 ms
47,888 KB
testcase_78 AC 349 ms
48,972 KB
testcase_79 AC 382 ms
50,444 KB
testcase_80 AC 378 ms
49,936 KB
testcase_81 AC 399 ms
49,812 KB
testcase_82 AC 409 ms
50,068 KB
testcase_83 AC 326 ms
49,172 KB
testcase_84 AC 339 ms
49,724 KB
testcase_85 AC 407 ms
51,568 KB
testcase_86 AC 323 ms
49,276 KB
testcase_87 AC 340 ms
49,820 KB
testcase_88 AC 372 ms
49,824 KB
testcase_89 AC 485 ms
53,636 KB
testcase_90 AC 449 ms
52,584 KB
testcase_91 AC 483 ms
52,980 KB
testcase_92 AC 450 ms
52,856 KB
testcase_93 AC 421 ms
52,608 KB
testcase_94 AC 435 ms
54,684 KB
testcase_95 AC 514 ms
55,568 KB
testcase_96 AC 387 ms
52,192 KB
testcase_97 AC 392 ms
51,572 KB
testcase_98 AC 179 ms
44,204 KB
testcase_99 AC 371 ms
53,148 KB
testcase_100 AC 464 ms
54,636 KB
testcase_101 AC 179 ms
44,412 KB
testcase_102 AC 201 ms
44,572 KB
testcase_103 AC 602 ms
62,356 KB
testcase_104 AC 48 ms
37,084 KB
testcase_105 AC 50 ms
37,036 KB
testcase_106 AC 47 ms
37,056 KB
testcase_107 AC 46 ms
36,992 KB
testcase_108 AC 46 ms
36,812 KB
testcase_109 AC 49 ms
36,820 KB
権限があれば一括ダウンロードができます

ソースコード

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 = "2 50\r\n" + 
//			"4 5\r\n" + 
//			"";
	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 = "10 500000 1 1 1 2 2 3 4 5 6 7";
//	String INPUT = "6 500000 5 7 11 13 17 23";
	
	long[][] bit;
	long ct = 0;
	
	void paint(long[] a, int s, int X, int K)
	{
		if(K < 32) {
			for(int i = s;i>>>6 == s>>>6;i+=K) {
				a[i>>>6] |= 1L<<i;
			}
			for(int j = (s>>>6)+1;j <= X>>>6;j++) {
				// s+ak >= j*64
				// a = (j*64-s+k-1)/k
				long first = (j*64-s+K-1)/K;
				long ss = s+first*K&63;
				a[j] |= bit[K][(int)ss];
			}
//			for(int i = s;i <= X;i+=K) {
//				a[i>>>6] |= 1L<<i;
//			}
		}else {
			for(int i = s;i <= X;i+=K) {
				ct++;
				a[i>>>6] |= 1L<<i;
			}
		}
	}
	
	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);
		
		bit = new long[32][32];
		for(int i = 1;i < 32;i++) {
			for(int j = 0;j < i;j++) {
				for(int k = j;k < 64;k+=i) {
					bit[i][j] |= 1L<<k;
				}
			}
		}
		
		long[][] dp = new long[de.all()][X/64+2];
		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]>>>6] |= 1L<<f[j][0];
					}else {
						int F = X;
						for(int w = 0;w < f.length;w++) {
							for(int k = f[w][1] - de.dec(i)[w] - (w == j ? 1 : 0);k > 0;k--) {
								F /= f[w][0]+1;
							}
						}
						F++;
						
//						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>>>6]<<~k<0) {
								paint(dp[ni], k*(l+1)+l, F, k);
//								for(int m = k*(l+1)+l;m <= X;m+=k) {
//									dp[ni][m>>>6] |= 1L<<m;
//								}
								if(k%l < 64) {
									if(h<<~(k%l)<0) {
										continue;
									}
									h |= 1L<<(k%l);
								}
								paint(dp[ni], k*(l+1)+l, F, l);
//								for(int m = k*(l+1)+l;m <= X;m+=l) {
////									ct++;
//									dp[ni][m>>>6] |= 1L<<m;
//								}
							}
						}
//						tr(i, j, ni, ct);
					}
				}
			}
		}
		for(int i = 1;i <= X;i++) {
			out.print(dp[de.all()-1][i>>>6]<<~i<0 ? 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