結果

問題 No.1245 ANDORゲーム(calc)
ユーザー startcppstartcpp
提出日時 2020-10-02 22:53:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 257 ms / 2,000 ms
コード長 735 bytes
コンパイル時間 568 ms
コンパイル使用メモリ 66,976 KB
実行使用メモリ 5,236 KB
最終ジャッジ日時 2023-09-24 22:26:23
合計ジャッジ時間 7,406 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 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 257 ms
5,072 KB
testcase_12 AC 254 ms
5,080 KB
testcase_13 AC 254 ms
5,084 KB
testcase_14 AC 252 ms
5,236 KB
testcase_15 AC 253 ms
5,100 KB
testcase_16 AC 251 ms
5,044 KB
testcase_17 AC 242 ms
5,108 KB
testcase_18 AC 238 ms
5,176 KB
testcase_19 AC 237 ms
5,056 KB
testcase_20 AC 247 ms
5,028 KB
testcase_21 AC 243 ms
5,048 KB
testcase_22 AC 239 ms
5,108 KB
testcase_23 AC 252 ms
5,064 KB
testcase_24 AC 253 ms
5,056 KB
testcase_25 AC 200 ms
5,048 KB
testcase_26 AC 209 ms
5,068 KB
testcase_27 AC 220 ms
5,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//実家
#include <iostream>
#include <string>
#include <algorithm>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n, q;
int a[100000];
string s;
int t[100000];
int memo[30][2];

signed main() {
	int i, j, k;
	
	cin >> n >> q;
	rep(i, n) cin >> a[i];
	cin >> s;
	rep(i, q) cin >> t[i];
	
	rep(i, 30) {
		rep(j, 2) {
			int x = j;
			int rng = 0;
			rep(k, n) {
				int val = (a[k] >> i) % 2;
				int nx;
				if (s[k] == '0') {
					nx = (x & val);
				}
				else {
					nx = (x | val);
				}
				rng += abs(nx - x);
				x = nx;
			}
			memo[i][j] = rng;
		}
	}
	
	rep(i, q) {
		int ans = 0;
		rep(j, 30) {
			ans += (memo[j][(t[i] >> j) % 2] << j);
		}
		cout << ans << endl;
	}
	
	return 0;
}
0