QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#278553#6512. Completely Multiplicative Functionucup-team1321#WA 37ms9092kbC++232.6kb2023-12-07 17:17:032023-12-07 17:17:05

Judging History

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

  • [2023-12-07 17:17:05]
  • 评测
  • 测评结果:WA
  • 用时:37ms
  • 内存:9092kb
  • [2023-12-07 17:17:03]
  • 提交

answer

#include <bits/stdc++.h>
#ifndef LOCAL
#define debug(...) 42
#else
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#endif
#define rep1(a) for (auto i = 0; i < a; i++)
#define rep2(i, a) for (auto i = 0; i < a; i++)
#define rep3(i, a, b) for (auto i = a; i < b; i++)
#define rep4(i, a, b, c) for (auto i = a; i < b; i += c)
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)

#define pb emplace_back
using namespace std;
template <typename T, typename T2> void cmin(T &x, const T2 &y) {
  x = x < y ? x : y;
}
template <typename T, typename T2> void cmax(T &x, const T2 &y) {
  x = x > y ? x : y;
}
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
template <class T> using vc = vector<T>;
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
mt19937 rng(time(NULL));
const int inf = 1000000000;
const ll lnf = 1000000000000000000;
#define sz(x) int((x).size())
#define all(x) begin(x), end(x)
#define fi first
#define se second

const int N = 1e6 + 5;
int isprime[N], prime[N], c = 0;
int f[N];
const int p[] = {2, 3, 5, 7, 11, 13, 17};
void solve() {
  int n, k;
  cin >> n >> k;
  if ((n + k) % 2 == 1) {
    cout << "-1\n";
    return;
  }
  vector<int> a;
  int cnt = 0;
  for (int i = 0; i < c; i++) {
    if (prime[i] > n) {
      break;
    } else if (prime[i] > n / 2) {
      cnt += 1;
    } else {
      a.pb(prime[i]);
    }
  }

  rep(s, 1 << 7) {
    vi b;
    rep(i, 7) if (s >> i & 1) b.pb(p[i]);
    for (int i = 1; i <= n; i++) f[i] = 1;
    for (int i = 2; i <= n; i++) {
      for (int x : b) {
        if (i % x == 0) {
          f[i] = -f[i / x];
          break;
        }
      }
    }
    int w = 0;
    for (int i = 1; i <= n; i++) w += f[i];
    if (w - cnt * 2 <= k && k <= w) {
      int t = (w - k) / 2;
      for (int i = n / 2 + 1; i < n; i++) {
        if (t == 0) {
          break;
        }
        if (isprime[i]) {
          f[i] = -1;
          t -= 1;
        }
      }
      for (int i = 1; i <= n; i++) {
        cout << f[i] << " \n"[i == n];
      }

      return;
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  rep(i, 2, N) isprime[i] = 1;
  rep(i, 2, N) {
    if (isprime[i]) {
      prime[c++] = i;
      for (int j = i * 2; j < N; j += i) {
        isprime[j] = 0;
      } 
    }
  }
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

详细

Test #1:

score: 100
Accepted
time: 8ms
memory: 9092kb

input:

4
4 2
10 0
10 1
10 10

output:

1 1 -1 1
1 -1 1 1 1 -1 -1 -1 1 -1
-1
1 1 1 1 1 1 1 1 1 1

result:

ok ok (4 test cases)

Test #2:

score: -100
Wrong Answer
time: 37ms
memory: 8712kb

input:

11475
1 0
1 1
2 0
2 1
2 2
3 0
3 1
3 2
3 3
4 0
4 1
4 2
4 3
4 4
5 0
5 1
5 2
5 3
5 4
5 5
6 0
6 1
6 2
6 3
6 4
6 5
6 6
7 0
7 1
7 2
7 3
7 4
7 5
7 6
7 7
8 0
8 1
8 2
8 3
8 4
8 5
8 6
8 7
8 8
9 0
9 1
9 2
9 3
9 4
9 5
9 6
9 7
9 8
9 9
10 0
10 1
10 2
10 3
10 4
10 5
10 6
10 7
10 8
10 9
10 10
11 0
11 1
11 2
11 3
11...

output:

-1
1
1 1
-1
1 1
-1
1 -1 1
-1
1 1 1
1 -1 -1 1
-1
1 1 -1 1
-1
1 1 1 1
-1
1 1 -1 1 1
-1
1 1 -1 1 1
-1
1 1 1 1 1
1 -1 1 1 -1 -1
-1
1 -1 1 1 1 -1
-1
1 1 1 1 -1 1
-1
1 1 1 1 1 1
-1
1 -1 1 1 -1 -1 1
-1
1 1 1 1 -1 1 1
-1
1 1 1 1 -1 1 1
-1
1 1 1 1 1 1 1
1 -1 1 1 -1 -1 1 -1
-1
1 -1 1 1 1 -1 1 -1
-1
1 1 1 1 -1...

result:

wrong answer sum of f is not k (test case 3)