結果

問題 No.1245 ANDORゲーム(calc)
ユーザー kotatsugame
提出日時 2020-10-02 21:48:07
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 262 ms / 2,000 ms
コード長 591 bytes
コンパイル時間 785 ms
コンパイル使用メモリ 67,992 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-16 04:43:36
合計ジャッジ時間 7,076 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    8 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;
int N,Q;
int A[1<<17];
string s;
long cost[30][2];
main()
{
	cin>>N>>Q;
	for(int i=0;i<N;i++)cin>>A[i];
	cin>>s;
	for(int i=0;i<30;i++)
	{
		for(int j=0;j<2;j++)
		{
			long sum=0;
			int msk=1<<i,now=j<<i;
			for(int k=0;k<N;k++)
			{
				int nxt;
				if(s[k]=='0')
				{
					nxt=now&(A[k]&msk);
				}
				else
				{
					nxt=now|(A[k]&msk);
				}
				sum+=abs(now-nxt);
				now=nxt;
			}
			cost[i][j]=sum;
		}
	}
	for(;Q--;)
	{
		int T;cin>>T;
		long ans=0;
		for(int i=0;i<30;i++)ans+=cost[i][T>>i&1];
		cout<<ans<<endl;
	}
}
0