結果
問題 | No.1245 ANDORゲーム(calc) |
ユーザー |
![]() |
提出日時 | 2020-10-03 19:29:35 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 282 ms / 2,000 ms |
コード長 | 780 bytes |
コンパイル時間 | 1,888 ms |
コンパイル使用メモリ | 197,240 KB |
最終ジャッジ日時 | 2025-01-15 02:13:46 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:24:16: warning: integer overflow in expression of type ‘int’ results in ‘2147483647’ [-Woverflow] 24 | int c=(1<<31)-1; | ~~~~~~~^~
ソースコード
#define rep(i,n) for(int i=0;i<(int)(n);i++)#define ALL(v) v.begin(),v.end()typedef long long ll;#include <bits/stdc++.h>using namespace std;int main(){int n,q;cin>>n>>q;vector<int> A(n);rep(i,n) cin>>A[i];string s;cin>>s;vector<int> D(q);rep(i,q) cin>>D[i];vector<ll> B(31),C(31);int b=0;int c=(1<<31)-1;for(int i=0;i<n;i++){int btmp=b,ctmp=c;if(s[i]=='0'){b=b&A[i];c=c&A[i];}else{b=b|A[i];c=c|A[i];}for(int j=0;j<31;j++){B[j]+=abs((b&(1<<j))-(btmp&(1<<j)));C[j]+=abs((c&(1<<j))-(ctmp&(1<<j)));}}rep(i,q){ll ans=0;rep(j,31){if(D[i]&(1<<j)) ans+=C[j];else ans+=B[j];}cout<<ans<<endl;}return 0;}