結果

問題 No.822 Bitwise AND
ユーザー kotatsugame
提出日時 2019-04-26 21:56:26
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 406 bytes
コンパイル時間 531 ms
コンパイル使用メモリ 64,620 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-25 18:12:31
合計ジャッジ時間 1,300 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:5:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    5 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
using namespace std;
int N,K;
long cnt;
main()
{
	cin>>N>>K;
	int id=0;
	while(N>>id)id++;
	int a=(1<<id)-1&~N;
	for(int i=0;i<1<<id;i++)
	{
		if(N&i)continue;
		int b=a&~i;
		for(int c=b;;c=c-1&b)
		{
			if(i>=c)
			{
				if(i-c<=K)
				{
					cnt++;
					if(c+(1<<id)-i<=K)
					{
						cout<<"INF"<<endl;
						return 0;
					}
				}
			}
			if(c==0)break;
		}
	}
	cout<<cnt<<endl;
}
0