답안 #51315

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
51315 2018-06-17T12:54:26 Z BrunoPloumhans CATS (NOI14_cats) C++14
25 / 25
520 ms 8660 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

int popcount(int x) {
  int ans = 0;
  while(x != 0) {
    ans += (x&1);
    x >>= 1;
  }
  return ans;
}

int greed(int x, int l, int n) {
  int k = (l+2*n-1)/(2*n);
  if(k < 60) {
    int period = 2LL << k;
    x %= period;
  }
  //cout << x << " " << period << endl;
  return k*2*n+popcount(x)%2;
}

int simulate(int x, int l, int n) {
  vector<int> st1(100000, 0);
  /*int period = (l+2*n-1)/(2*n)*4;
    x %= period;*/
  int t2;
  int counter = x+1;
  while(counter > 0) {
    t2 = st1.back();
    st1.pop_back();
    for(int& i : st1) i ^= 1;
    if(t2 > l) {
      --counter;
      cout << x-counter << ": " << t2 << endl;
    } else {
      t2 += 2*n;
      st1.push_back(t2);
      st1.push_back(t2);
    }
  }
  return t2;
}

signed main() {
  int q;
  cin >> q;
  while(q--) {
    int x, l, n;
    cin >> x >> l >> n; --x;
    cout << greed(x, l, n) /*<< " " << greed(x, l, n)*/ << '\n';
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 548 KB Output is correct
2 Correct 2 ms 548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 556 KB Output is correct
2 Correct 4 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 604 KB Output is correct
2 Correct 6 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 748 KB Output is correct
2 Correct 48 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 374 ms 2876 KB Output is correct
2 Correct 520 ms 8660 KB Output is correct