結果

問題 No.822 Bitwise AND
ユーザー kuuso1kuuso1
提出日時 2019-04-26 23:15:39
言語 C#(csc)
(csc 3.9.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,690 bytes
コンパイル時間 3,071 ms
コンパイル使用メモリ 105,408 KB
実行使用メモリ 22,916 KB
最終ジャッジ日時 2023-09-08 01:11:43
合計ジャッジ時間 4,981 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 57 ms
18,696 KB
testcase_02 AC 58 ms
20,800 KB
testcase_03 AC 56 ms
20,828 KB
testcase_04 AC 57 ms
22,740 KB
testcase_05 AC 59 ms
20,700 KB
testcase_06 AC 59 ms
20,680 KB
testcase_07 AC 58 ms
22,740 KB
testcase_08 AC 58 ms
20,740 KB
testcase_09 AC 57 ms
22,728 KB
testcase_10 AC 57 ms
20,708 KB
testcase_11 AC 57 ms
22,804 KB
testcase_12 AC 59 ms
20,828 KB
testcase_13 AC 59 ms
22,860 KB
testcase_14 AC 56 ms
20,868 KB
testcase_15 AC 58 ms
20,800 KB
testcase_16 AC 60 ms
20,872 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long l = 0;
		long r = 0;
		long d = 1;
		for(int i=0;i<32;i++){
			if((N >> i) % 2 == 1){
				d *= 2;
				continue;
			}
			r += d;
			l -= d;
			d *= 2;
		}
		
		if(r - d <= K && r - d >= -K){
			Console.WriteLine("INF");
			return;
		}
		
		
		
		int Kmax = 300;
		int Ofs = 2 * Kmax;
		long[] dp = new long[4 * Kmax];
		dp[0 + Ofs] = 1;
		long v = 1;
		for(int i=0;i<31;i++){
			if((N >> i) % 2 == 1){
				v *= 2;
				continue;
			}
			var ndp = new long[4 * Kmax];
			for(int j=0;j< 4 * Kmax;j++){
				if(dp[j] == 0) continue;
				ndp[j] += dp[j];
				if(j + v < 4 * Kmax) ndp[j + v] += dp[j];
				if(j - v >= 0 ) ndp[j - v] += dp[j];
			}
			dp = ndp;
			v *= 2;
		}
		
		long ans = 0;
		for(int i=0;i<=K;i++) ans += dp[i + Ofs];
		Console.WriteLine(ans);
		
	}
	int N,K;
	public Sol(){
		var d = ria();
		N = d[0]; K = d[1];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}
0