結果

問題 No.1245 ANDORゲーム(calc)
ユーザー kotatsugamekotatsugame
提出日時 2020-10-02 21:48:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 251 ms / 2,000 ms
コード長 591 bytes
コンパイル時間 598 ms
コンパイル使用メモリ 67,004 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-23 04:38:48
合計ジャッジ時間 7,266 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 6 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 6 ms
4,376 KB
testcase_10 AC 8 ms
4,380 KB
testcase_11 AC 250 ms
4,376 KB
testcase_12 AC 249 ms
4,376 KB
testcase_13 AC 250 ms
4,380 KB
testcase_14 AC 248 ms
4,376 KB
testcase_15 AC 251 ms
4,376 KB
testcase_16 AC 250 ms
4,380 KB
testcase_17 AC 245 ms
4,380 KB
testcase_18 AC 235 ms
4,380 KB
testcase_19 AC 235 ms
4,380 KB
testcase_20 AC 244 ms
4,376 KB
testcase_21 AC 241 ms
4,376 KB
testcase_22 AC 235 ms
4,376 KB
testcase_23 AC 250 ms
4,380 KB
testcase_24 AC 251 ms
4,380 KB
testcase_25 AC 200 ms
4,376 KB
testcase_26 AC 202 ms
4,380 KB
testcase_27 AC 216 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-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