답안 #276930

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
276930 2020-08-20T19:39:28 Z caoash CATS (NOI14_cats) C++14
12 / 25
60 ms 2336 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 * X) + 2 <= 62) X %= (1LL << (L / (2 * N) + 2));
    cout << (2 * N) * ((L / (2 * N)) + 1) + (__builtin_popcount(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);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 60 ms 2336 KB Output isn't correct
2 Halted 0 ms 0 KB -