QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#276603#7610. Bus LinesAllTheWayNorth#WA 3078ms21536kbC++144.1kb2023-12-05 23:42:032023-12-05 23:42:03

Judging History

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

  • [2023-12-05 23:42:03]
  • 评测
  • 测评结果:WA
  • 用时:3078ms
  • 内存:21536kb
  • [2023-12-05 23:42:03]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int M = 150;
int power(int a, int b) {
    long long res = a, ans = 1;
    for (; b; b >>= 1, res = res * res % mod) if (b & 1) ans = ans * res % mod;
    return ans;
}

int qry[15], ans[15];
vector < pair <int, int> > eans[15];

struct node {
    int n;
    vector <int> L[M], R[M];
    int f[M];
    void build(int N) {
        memset(f, 0, sizeof f);
        for (int i = 0; i < M; i++) L[i].clear(), R[i].clear();
        n = N;
        f[0] = 1;
        for (int i = 1; i <= n - 2; i++) f[i] = 1ll * f[i - 1] * (n - i - 1) % mod;
        L[0].push_back(1);
        R[0].push_back(1);
        int l = 1, r = n - 2;
        while (l <= r) {
            int suml = 0, sumr = 0;
            for (int i = 0; i <= n - 2; i++) suml += (n - 2 - i + l) / l * L[i].size();
            for (int i = 0; i <= n - 2; i++) sumr += (n - 2 - i + r) / r * R[i].size();
            if (suml < sumr) {
                int inv = power(f[l], mod - 2);
                for (int i = 0; i + l <= n - 2; i++) {
                    for (auto j : L[i]) L[i + l].push_back(1ll * j * inv % mod);
                }
                l++;
            }
            else {
                for (int i = 0; i + r <= n - 2; i++) {
                    for (auto j : R[i]) R[i + r].push_back(1ll * j * f[r] % mod), sumr++;
                }
                r--;
            }
        }
        for (int i = 0; i <= n - 2; i++) {
            sort(L[i].begin(), L[i].end());
            L[i].resize(unique(L[i].begin(), L[i].end()) - L[i].begin());
        }
        for (int i = 0; i <= n - 2; i++) {
            sort(R[i].begin(), R[i].end());
            R[i].resize(unique(R[i].begin(), R[i].end()) - R[i].begin());
        }
    }
    vector < pair <int, int> > query(int v) {
        v = 1ll * v * power(1ll * n * (n - 1) % mod, mod - 2) % mod;
        for (int i = 0; i <= n - 2; i++) {
            for (auto j : L[i]) {
                int cur = 1ll * v * j % mod;
                auto ite = lower_bound(R[n - 2 - i].begin(), R[n - 2 - i].end(), cur);
                if (ite == R[n - 2 - i].end() || *ite != cur) continue;
                vector < pair <int, int> > ans{{1, 2}};
                int p = 2, tmp = j, rst = i;
                for (int t = 1; t <= rst; t++) {
                    while (rst >= t) {
                        int nxt = 1ll * tmp * f[t] % mod;
                        auto ite = lower_bound(L[rst - t].begin(), L[rst - t].end(), nxt);
                        if (ite == L[rst - t].end() || *ite != nxt) break;
                        rst -= t, tmp = nxt;
                        for (int x = 1; x <= t; x++) ans.push_back({p, p + x});
                        p += t;
                    }
                }
                assert(tmp == 1 && rst == 0);
                tmp = cur, rst = n - 2 - i;
                for (int t = 1; t <= rst; t++) {
                    while (rst >= t) {
                        int nxt = 1ll * tmp * power(f[t], mod - 2) % mod;
                        auto ite = lower_bound(R[rst - t].begin(), R[rst - t].end(), nxt);
                        if (ite == R[rst - t].end() || *ite != nxt) break;
                        rst -= t, tmp = nxt;
                        for (int x = 1; x <= t; x++) ans.push_back({p, p + x});
                        p += t;
                    }
                }
                assert(tmp == 1 && rst == 0);
                fflush(stdout);
                return ans;
            }
        }
        return {};
    }
} a;

int main() {
    int T;
    scanf("%d", &T);
    int rst = T;
    for (int i = 1; i <= T; i++) {
        scanf("%d", qry + i);
        if (qry[i] == 1) ans[i] = 1, rst--;
    }
    for (int i = 2; rst; i++) {
        a.build(i);
        for (int i = 1; i <= T; i++) if (ans[i] == 0) {
            eans[i] = a.query(qry[i]);
            if (eans[i].size()) ans[i] = eans[i].size() + 1, rst--;
        }
    }
    for (int i = 1; i <= T; i++) {
        printf("%d\n", ans[i]);
        for (auto j : eans[i]) printf("%d %d\n", j.first, j.second);
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 3078ms
memory: 21536kb

input:

6
1 2
5 4
6 5
3 1
1 5
3
6 1
2 3
6 4

output:

1
2
1 2
106
1 2
2 3
3 4
4 5
5 6
6 7
7 8
7 9
9 10
9 11
9 12
12 13
12 14
12 15
15 16
15 17
15 18
15 19
19 20
19 21
19 22
19 23
23 24
23 25
23 26
23 27
27 28
27 29
27 30
27 31
31 32
31 33
31 34
31 35
35 36
35 37
35 38
35 39
39 40
39 41
39 42
39 43
39 44
39 45
39 46
39 47
47 48
47 49
47 50
47 51
47 52
4...

result:

wrong answer 1st lines differ - expected: '6 9 9 10 7 7', found: '1'