結果
| 問題 |
No.1296 OR or NOR
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2020-06-24 17:40:28 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,152 bytes |
| コンパイル時間 | 2,114 ms |
| コンパイル使用メモリ | 199,080 KB |
| 最終ジャッジ日時 | 2025-01-11 09:52:41 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 30 WA * 3 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:39:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
39 | for(int i=0;i<N;i++)scanf("%lld",&a[i]);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:65:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
65 | scanf("%lld",&b);
| ~~~~~^~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000
int check(vector<pair<long long,int>> &base,long long t,char last){
long long now = 0LL;
string S = "1";
for(int i=0;i<base.size();i++){
if((t>>base[i].second)&1){
now ^= base[i].first;
S += '1';
}
else{
S += '0';
}
}
if(now!=t)return 100;
int ret = 0;
S += last;
for(int i=1;i<S.size();i++){
if(S[i]!=S[i-1])ret++;
}
return ret;
}
int main(){
long long X = (1LL<<60)-1;
int N;
cin>>N;
vector<long long> a(N);
for(int i=0;i<N;i++)scanf("%lld",&a[i]);
long long now = X;
vector<pair<long long,int>> base;
for(int i=N-1;i>=0;i--){
long long t = now&a[i];
for(int j=59;j>=0;j--){
if((t>>j)&1){
base.emplace_back(t,j);
break;
}
}
now &= a[i]^X;
}
reverse(base.begin(),base.end());
long long t = now&a[0];
int Q;
cin>>Q;
for(int i=0;i<Q;i++){
long long b;
scanf("%lld",&b);
int ans = min(check(base,b^t,'1'),check(base,b^X^t,'0'));
if(ans==100)printf("-1\n");
else printf("%d\n",ans);
}
return 0;
}
沙耶花