QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#186816#4912. WereYouLasthos_lyric#34 4633ms5004kbC++142.4kb2023-09-24 12:07:562024-07-04 02:08:24

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 02:08:24]
  • 评测
  • 测评结果:34
  • 用时:4633ms
  • 内存:5004kb
  • [2023-09-24 12:07:56]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")

bool query(int);
void modify(int,bool);

bool WereYouLast(int N, int M) {
  if (M == 10) {
    int x = 0;
    for (int i = 0; i < M; ++i) {
      if (query(i + 1)) {
        x |= 1 << i;
      }
    }
    if (x == (1 << M) - 1) {
      return true;
    }
    for (int i = 0; i < M; ++i) {
      modify(i + 1, (x + 1) >> i & 1);
    }
    return false;
  } else {
    const int E = 31 - __builtin_clz(N);
    int segN = 1;
    for (; segN < E; segN <<= 1) {}
    int u;
    if (query(M)) {
      // odd -> even
      // gray code: change (bsf + 1)
      modify(M, false);
      u = 1;
      for (; u < segN; ) {
        if (query(u << 1)) {
          u = u << 1;
        } else {
          u = u << 1 | 1;
        }
      }
      if (++u == segN + E) {
        return true;
      }
    } else {
      // even -> odd
      // gray code: change 0
      modify(M, true);
      u = segN;
    }
    modify(u, !query(u));
    for (; ; ) {
      const int v = u;
      u >>= 1;
      if (!(u & (u + 1))) break;
      const bool crt = query(u);
      const bool nxt = query(v) || query((u << 1) ^ (u << 1 | 1) ^ v);
      if (crt == nxt) break;
      modify(u, nxt);
    }
    return false;
  }
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 1ms
memory: 3960kb

input:

1024 10

output:

12345876 10 10

result:

ok Correct Answer.
C1 = 10.
C2 = 10.

Subtask #2:

score: 10
Acceptable Answer

Test #2:

score: 10
Acceptable Answer
time: 5ms
memory: 5004kb

input:

65536 100000

output:

12345876 10 10

result:

points 0.50 Correct Answer.
C1 = 10.
C2 = 10.

Subtask #3:

score: 6
Acceptable Answer

Test #3:

score: 6
Acceptable Answer
time: 73ms
memory: 5000kb

input:

1048576 100000

output:

12345876 13 13

result:

points 0.20 Correct Answer.
C1 = 13.
C2 = 13.

Subtask #4:

score: 8
Acceptable Answer

Test #4:

score: 8
Acceptable Answer
time: 4633ms
memory: 4932kb

input:

67108864 100000

output:

12345876 13 13

result:

points 0.20 Correct Answer.
C1 = 13.
C2 = 13.