結果

問題 No.1246 ANDORゲーム(max)
コンテスト
ユーザー kotatsugame
提出日時 2020-10-02 22:12:20
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 327 ms / 2,000 ms
コード長 439 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 588 ms
コンパイル使用メモリ 96,888 KB
実行使用メモリ 104,732 KB
最終ジャッジ日時 2026-04-01 12:26:46
合計ジャッジ時間 6,213 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    7 | main()
      | ^~~~

ソースコード

diff #
raw source code

#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int N,T;
map<int,long>mp;
main()
{
	cin>>N>>T;
	mp[T]=0;
	for(;N--;)
	{
		int A;cin>>A;
		map<int,long>nxt;
		for(pair<int,long>p:mp)
		{
			int q=p.first&A;
			nxt[q]=max(nxt[q],p.second+abs(p.first-q));
			q=p.first|A;
			nxt[q]=max(nxt[q],p.second+abs(p.first-q));
		}
		mp=nxt;
	}
	long ans=0;
	for(pair<int,long>p:mp)ans=max(ans,p.second);
	cout<<ans<<endl;
}
0