QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#235252#7613. Inverse ProblemdykwWA 18088ms127376kbC++203.3kb2023-11-02 16:27:422023-11-02 16:27:44

Judging History

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

  • [2023-11-02 16:27:44]
  • 评测
  • 测评结果:WA
  • 用时:18088ms
  • 内存:127376kb
  • [2023-11-02 16:27:42]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

constexpr int maxn = 125;
constexpr int mod = (int) 1e9 + 7;

bitset<mod> f;
int t;
int r[10];
vector<int> rid;
int w[126][126], iw[126][126], inv[126];
vector<pair<int, int>> g[126], h[126];

void dfs(int x, int used, int res, const int &n) {
  f[res] = 1;
  for (int i = x; i <= min(n - 2, 6); ++i) {
    if (used + i > n - 2) {
      break;
    }
    dfs(i, used + i, 1LL * res * w[n - 2][i] % mod, n);
  }
}

void dfs_b(int x, int used, int res, const int &n) {
  for (int i : rid) {
    if (f[1LL * r[i] * inv[n] % mod * inv[n - 1] % mod * res % mod]) {
      g[used].emplace_back(i, res);
    }
  }
  for (int i = x; i <= n - 2; ++i) {
    if (used + i > n - 2) {
      break;
    }
    dfs_b(i, used + i, 1LL * res * iw[n - 2][i] % mod, n);
  }
}

int ans_n[10];
vector<int> tmp;
vector<int> siz[10];

void dfs_chk(int x, int used, int res, const int &n) {
  for (auto [i, v] : g[n - 2 - used]) {
    if (1LL * res * n % mod * (n - 1) % mod == 1LL * r[i] * v % mod) {
      ans_n[i] = n;
      siz[i] = tmp;
      h[n - 2 - used].emplace_back(i, v);
    }
  }
  for (int i = x; i <= min(6, n - 2); ++i) {
    if (used + i > n - 2) {
      break;
    }
    tmp.push_back(i);
    dfs_chk(i, used + i, 1LL * res * w[n - 2][i] % mod, n);
    tmp.pop_back();
  }
}

void dfs_rem(int x, int used, int res, const int &n) {
  for (auto [i, v] : h[used]) {
    if (res == v) {
      for (int u : tmp) {
        siz[i].push_back(u);
      }
    }
  }
  for (int i = x; i <= n - 2; ++i) {
    if (used + i > n - 2) {
      break;
    }
    tmp.push_back(i);
    dfs_rem(i, used + i, 1LL * res * iw[n - 2][i] % mod, n);
    tmp.pop_back();
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  cin >> t;
  for (int i = 0; i < t; ++i) {
    cin >> r[i];
    if (r[i] == 1) {
      ans_n[i] = 1;
    } else if (r[i] == 2) {
      ans_n[i] = 2;
    } else {
      rid.push_back(i);
    }
  }
  
  inv[1] = 1;
  for (int i = 2; i <= 125; ++i) {
    inv[i] = 1LL * (mod - mod / i) * inv[mod % i] % mod;
  }
  for (int i = 1; i <= 125; ++i) {
    w[i][0] = iw[i][0] = 1;
    for (int j = 1; j <= i; ++j) {
      w[i][j] = 1LL * w[i][j - 1] * (i - j + 1) % mod;
      iw[i][j] = 1LL * iw[i][j - 1] * inv[i - j + 1] % mod;
    }
  }
  
  auto clk = clock();
  for (int n = 3; n <= maxn; ++n) {
    if (rid.empty()) {
      break;
    }
    f.reset();
    for (int i = 0; i <= n; ++i) {
      g[i].clear();
      h[i].clear();
    }
    dfs(1, 0, 1, n);
    dfs_b(7, 0, 1, n);
    dfs_chk(1, 0, 1, n);
    assert(tmp.empty());
    dfs_rem(7, 0, 1, n);
    for (int i = 0; i < t; ++i) {
      if (ans_n[i] != 0 && find(rid.begin(), rid.end(), i) != rid.end()) {
        rid.erase(find(rid.begin(), rid.end(), i));
      }
    }
  }
  cerr << "Elp: " << clock() - clk << '\n';
  
  for (int i = 0; i < t; ++i) {
    cout << ans_n[i] << '\n';
    if (ans_n[i] == 2) {
      cout << "1 2" << '\n';
    } else if (ans_n[i] != 1) {
      cout << "1 2" << '\n';
      int lst = 2;
      for (int k : siz[i]) {
        int now = lst;
        while (k--) {
          ++now;
          cout << lst << ' ' << now << '\n';
        }
        lst = now;
      }
    }
  }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 73ms
memory: 125692kb

input:

4
2
360
1
509949433

output:

2
1 2
5
1 2
2 3
3 4
3 5
1
10
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10

result:

ok OK (4 test cases)

Test #2:

score: -100
Wrong Answer
time: 18088ms
memory: 127376kb

input:

9
185396120
468170792
837583517
696626231
338497514
762842660
800028852
928391161
733524004

output:

14
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
10 12
12 13
12 14
122
1 2
2 3
3 4
4 5
5 6
6 7
7 8
7 9
9 10
9 11
11 12
11 13
13 14
13 15
13 16
16 17
16 18
16 19
19 20
19 21
19 22
22 23
22 24
22 25
22 26
26 27
26 28
26 29
26 30
30 31
30 32
30 33
30 34
30 35
35 36
35 37
35 38
35 39
35 40
35 41
35 42
42 4...

result:

wrong answer Integer 123 violates the range [1, 122]