提出 #29119464


ソースコード 拡げる

// #include <atcoder/all>
// using namespace atcoder;
// using mint = modint998244353;
// using mint = modint1000000007;
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,k,n) for (int i = (k); i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
// using P = pair<int,int>;
using vint = vector<int>;
using vll = vector<ll>;
using vvint = vector<vector<int>>;
using vvll = vector<vector<ll>>;

// const ll INF = (ll)2e18+9;
const int INF = (int)2e9+7;
// const ll MOD = (ll)1e9+9;
template<typename T>
void chmin(T &a, T b) { a = min(a, b); }
template<typename T>
void chmax(T &a, T b) { a = max(a, b); }

template<typename T>
void print(vector<T> v) {
    int n = v.size();
    rep(i,n) {
        if (i == 0) cout << v[i];
        else cout << ' ' << v[i];
    }
    cout << endl;
}

map<P, bool> mp;
bool cal(ll a, ll s) {
    if (s == 0) return a==0;
    P p = {a,s};
    if (mp.count(p)) return mp[p];
    rep(x,2) rep(y,2) {
        // 1 bit ずつ調べていく
        if ((x&y) != (a&1)) continue;
        if ((s-(x+y)) < 0) continue;
        if ((s-(x+y))%2 != 0) continue;
        if (cal(a>>1, (s-(x+y))>>1)) return mp[p] = true;
    }
    return mp[p] = false;
}

void solve() {
    int t;
    cin >> t;
    rep(i,t) {
        ll a, s;
        cin >> a >> s;
        mp = map<P,bool>();
        if (cal(a,s)) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

int main() {
    solve();
    return 0;
}

提出情報

提出日時
問題 D - AND and SUM
ユーザ goropikari
言語 C++ (GCC 9.2.1)
得点 400
コード長 1641 Byte
結果 AC
実行時間 430 ms
メモリ 3588 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 2
AC × 13
セット名 テストケース
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, example0.txt, example1.txt
ケース名 結果 実行時間 メモリ
000.txt AC 7 ms 3476 KiB
001.txt AC 365 ms 3468 KiB
002.txt AC 83 ms 3544 KiB
003.txt AC 421 ms 3568 KiB
004.txt AC 430 ms 3588 KiB
005.txt AC 425 ms 3540 KiB
006.txt AC 426 ms 3472 KiB
007.txt AC 425 ms 3452 KiB
008.txt AC 428 ms 3428 KiB
009.txt AC 427 ms 3428 KiB
010.txt AC 244 ms 3416 KiB
example0.txt AC 8 ms 3464 KiB
example1.txt AC 2 ms 3472 KiB