結果
問題 | No.1245 ANDORゲーム(calc) |
ユーザー | fura |
提出日時 | 2020-10-02 22:31:12 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 133 ms / 2,000 ms |
コード長 | 616 bytes |
コンパイル時間 | 1,806 ms |
コンパイル使用メモリ | 194,148 KB |
最終ジャッジ日時 | 2025-01-15 00:43:20 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:9:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 9 | int n,q; scanf("%d%d",&n,&q); | ~~~~~^~~~~~~~~~~~~~ main.cpp:11:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 11 | rep(i,n) scanf("%d",&a[i]); | ~~~~~^~~~~~~~~~~~ main.cpp:32:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 32 | int t; scanf("%d",&t); | ~~~~~^~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; using lint=long long; int main(){ int n,q; scanf("%d%d",&n,&q); vector<int> a(n); rep(i,n) scanf("%d",&a[i]); string s; cin>>s; lint sum[30][2]={}; rep(d,30){ sum[d][0]=0; int x; rep(j,2){ x=j; rep(i,n){ if(s[i]=='0'){ // and if(x==1 && (a[i]>>d&1)==0) sum[d][j]+=1LL<<d, x=0; } else{ // or if(x==0 && (a[i]>>d&1)==1) sum[d][j]+=1LL<<d, x=1; } } } } rep(_,q){ int t; scanf("%d",&t); lint ans=0; rep(d,30) ans+=sum[d][t>>d&1]; printf("%lld\n",ans); } return 0; }