結果

問題 No.941 商とあまり
ユーザー uwiuwi
提出日時 2019-12-04 03:43:56
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 5,914 bytes
コンパイル時間 6,009 ms
コンパイル使用メモリ 86,392 KB
実行使用メモリ 275,040 KB
最終ジャッジ日時 2024-11-28 19:15:56
合計ジャッジ時間 78,470 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 358 ms
66,784 KB
testcase_01 AC 210 ms
275,040 KB
testcase_02 AC 227 ms
50,524 KB
testcase_03 AC 206 ms
44,992 KB
testcase_04 AC 211 ms
43,796 KB
testcase_05 AC 212 ms
44,264 KB
testcase_06 AC 199 ms
44,048 KB
testcase_07 AC 240 ms
48,756 KB
testcase_08 AC 245 ms
48,068 KB
testcase_09 AC 231 ms
47,932 KB
testcase_10 AC 241 ms
53,012 KB
testcase_11 AC 260 ms
50,928 KB
testcase_12 AC 220 ms
47,200 KB
testcase_13 AC 310 ms
56,988 KB
testcase_14 AC 271 ms
49,940 KB
testcase_15 AC 315 ms
59,340 KB
testcase_16 AC 383 ms
63,288 KB
testcase_17 AC 479 ms
65,228 KB
testcase_18 AC 821 ms
89,012 KB
testcase_19 TLE -
testcase_20 AC 206 ms
44,216 KB
testcase_21 AC 217 ms
45,028 KB
testcase_22 AC 209 ms
44,752 KB
testcase_23 AC 52 ms
37,144 KB
testcase_24 AC 52 ms
37,152 KB
testcase_25 AC 50 ms
36,996 KB
testcase_26 AC 296 ms
52,740 KB
testcase_27 AC 304 ms
57,888 KB
testcase_28 AC 270 ms
49,480 KB
testcase_29 AC 425 ms
66,296 KB
testcase_30 AC 426 ms
66,408 KB
testcase_31 AC 275 ms
49,332 KB
testcase_32 AC 210 ms
46,900 KB
testcase_33 AC 197 ms
44,324 KB
testcase_34 AC 846 ms
89,148 KB
testcase_35 AC 766 ms
86,816 KB
testcase_36 AC 242 ms
48,020 KB
testcase_37 AC 261 ms
48,068 KB
testcase_38 AC 234 ms
48,008 KB
testcase_39 AC 249 ms
47,916 KB
testcase_40 AC 195 ms
44,676 KB
testcase_41 AC 193 ms
44,560 KB
testcase_42 AC 206 ms
44,328 KB
testcase_43 AC 252 ms
47,948 KB
testcase_44 AC 247 ms
47,936 KB
testcase_45 AC 1,727 ms
126,860 KB
testcase_46 AC 795 ms
89,280 KB
testcase_47 AC 265 ms
49,736 KB
testcase_48 AC 195 ms
44,484 KB
testcase_49 AC 285 ms
56,040 KB
testcase_50 AC 253 ms
50,328 KB
testcase_51 AC 277 ms
50,680 KB
testcase_52 AC 256 ms
49,120 KB
testcase_53 AC 268 ms
50,352 KB
testcase_54 AC 1,951 ms
162,676 KB
testcase_55 TLE -
testcase_56 AC 1,875 ms
162,556 KB
testcase_57 TLE -
testcase_58 TLE -
testcase_59 AC 246 ms
47,396 KB
testcase_60 AC 276 ms
47,176 KB
testcase_61 AC 227 ms
45,856 KB
testcase_62 AC 269 ms
48,144 KB
testcase_63 AC 251 ms
47,556 KB
testcase_64 AC 252 ms
48,388 KB
testcase_65 AC 262 ms
49,856 KB
testcase_66 AC 295 ms
48,704 KB
testcase_67 AC 281 ms
49,836 KB
testcase_68 AC 275 ms
48,208 KB
testcase_69 AC 354 ms
55,948 KB
testcase_70 AC 413 ms
60,360 KB
testcase_71 AC 289 ms
51,980 KB
testcase_72 AC 288 ms
51,880 KB
testcase_73 AC 423 ms
60,632 KB
testcase_74 AC 603 ms
66,392 KB
testcase_75 AC 476 ms
62,092 KB
testcase_76 AC 459 ms
60,228 KB
testcase_77 AC 346 ms
57,620 KB
testcase_78 AC 646 ms
66,476 KB
testcase_79 AC 749 ms
80,112 KB
testcase_80 AC 786 ms
79,916 KB
testcase_81 AC 907 ms
83,988 KB
testcase_82 AC 782 ms
80,140 KB
testcase_83 AC 470 ms
64,332 KB
testcase_84 AC 769 ms
80,048 KB
testcase_85 AC 1,131 ms
94,668 KB
testcase_86 AC 747 ms
77,848 KB
testcase_87 AC 701 ms
77,820 KB
testcase_88 AC 764 ms
80,260 KB
testcase_89 AC 1,753 ms
112,736 KB
testcase_90 AC 1,437 ms
103,888 KB
testcase_91 AC 1,759 ms
103,724 KB
testcase_92 AC 1,653 ms
106,848 KB
testcase_93 AC 1,559 ms
103,840 KB
testcase_94 AC 1,666 ms
126,852 KB
testcase_95 TLE -
testcase_96 AC 1,137 ms
100,268 KB
testcase_97 AC 1,028 ms
94,676 KB
testcase_98 AC 195 ms
43,952 KB
testcase_99 AC 1,210 ms
103,696 KB
testcase_100 AC 1,868 ms
125,932 KB
testcase_101 AC 195 ms
44,588 KB
testcase_102 AC 197 ms
44,008 KB
testcase_103 TLE -
testcase_104 AC 53 ms
37,364 KB
testcase_105 AC 53 ms
37,016 KB
testcase_106 AC 52 ms
37,204 KB
testcase_107 AC 53 ms
37,100 KB
testcase_108 AC 52 ms
36,868 KB
testcase_109 AC 53 ms
252,000 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 = "";
//	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