Submission #276935

# Submission time Handle Problem Language Result Execution time Memory
276935 2020-08-20T19:52:22 Z caoash CATS (NOI14_cats) C++14
25 / 25
74 ms 8108 KB
    #include <bits/stdc++.h> 
    using namespace std;

    using ll = long long;

    using vi = vector<int>;
    #define pb push_back
    #define rsz resize
    #define all(x) begin(x), end(x)
    #define sz(x) (int)(x).size()

    using pi = pair<int,int>;
    #define f first
    #define s second
    #define mp make_pair

    void solve(int X, int L, int N){
        int cnt = X;
        vi s1, s2;
        int b = 0;
        s1.pb(0);
        while (cnt > 0) {
            s2.pb(s1.back());
            s1.pop_back();
            if (s1.empty()) {
                s1.pb(b);
            }
            for (int i = 0; i < sz(s1); i++) {
                s1[i] = s1[i] ^ 1;
            }
            b ^= 1;
            if (s2.back() > L) {
                cnt--;
                if (cnt == 0) {
                    cout << s2.back() << '\n';
                    // cout << "answer: " << s2.back() << "\n";
                    return;
                }
            }
            else {
                s2[sz(s2) - 1] += 2 * N;
                s1.pb(s2[sz(s2) - 1]);
                s1.pb(s2[sz(s2) - 1]);
                if(!s2.empty()) s2.pop_back();
                if(!s2.empty()) s2.pop_back();
            }
        }
    }

    void solveSmart(ll X, ll L, ll N) {
        X--;
        if (L / (2 * N) + 2 <= 62) X %= (1LL << (L / (2 * N) + 2));
        cout << 2 * N * (L / (2 * N) + 1) + __builtin_popcountll(X) % 2 << '\n';
    }

    int main(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        int Q; cin >> Q;
        while (Q--) {
            ll X, L, N; cin >> X >> L >> N;
            solveSmart(X, L, N);
        }
    }
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 2296 KB Output is correct
2 Correct 74 ms 8108 KB Output is correct