QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#296006#7613. Inverse Problembachbeo2007AC ✓31340ms138900kbC++234.6kb2024-01-01 21:50:312024-01-01 21:50:32

Judging History

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

  • [2024-01-01 21:50:32]
  • 评测
  • 测评结果:AC
  • 用时:31340ms
  • 内存:138900kb
  • [2024-01-01 21:50:31]
  • 提交

answer

// Judges with GCC >= 12 only needs Ofast
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// MLE optimization
// #pragma GCC optimize("conserve-stack")
// Old judges
// #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2")
// New judges. Test with assert(__builtin_cpu_supports("avx2"));
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
// Atcoder
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
- insert(x),erase(x)
- find_by_order(k): return iterator to the k-th smallest element
- order_of_key(x): the number of elements that are strictly smaller
*/
#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define int long long
#define ld long double
#define pii pair<int,int>
#define piii pair<int,pii>
#define mpp make_pair
#define fi first
#define se second
const int inf=1e18;
const int mod=1e9+7;
const int maxn=130;
const int bl=650;
const int maxs=655;
const int maxm=200005;
const int maxq=1000005;
const int maxl=25;
const int maxa=1000000;
const int root=3;
int power(int a,int n){
    int res=1;
    while(n){
        if(n&1) res=res*a%mod;
        a=a*a%mod;n>>=1;
    }
    return res;
}
const int iroot=power(3,mod-2);
const int base=131;

const int N = 125;

int inv[maxn],w[maxn][maxn],iw[maxn][maxn];

int r[maxn],ans[maxn];
vector<int> deg[maxn];
vector<int> rid;

void build(){
    inv[1]=1;
    for(int i=2;i<=N;i++) inv[i]=mod-(mod/i)*inv[mod%i]%mod;

    for(int i=1;i<=N;i++){
        w[i][0]=iw[i][0]=1;
        for(int j=1;j<=i;j++){
            w[i][j]=w[i][j-1]*(i-j+1)%mod;
            iw[i][j]=iw[i][j-1]*inv[i-j+1]%mod;
        }
    }
}

void print(int n,vector<int> d){
    while(n>1 && (int)d.size()<n) d.push_back(0);
    for(int &x:d) x++;
    sort(d.begin(),d.end());
    vector<pii> edge;
    for(int i=0;i<(int)d.size();i++){
        for(int j=i+1;j<(int)d.size();j++){
            if(d[j]>1 || i==(int)d.size()-2){
                d[i]--;d[j]--;
                edge.push_back({i,j});
                break;
            }
        }
    }
    cout << n << '\n';
    for(auto x:edge) cout << x.fi+1 << ' ' << x.se+1 << '\n';
}

bitset<mod> f;
vector<pii> h[maxn],g[maxn];
int n;

void dfs_a(int x,int used,int cur){
    f[cur]=1;
    for(int i=x;i<=min(n-2,6LL);i++){
        if(used+i>n-2) return;
        dfs_a(i,used+i,cur*w[n-2][i]%mod);
    }
}
void dfs_b(int x,int used,int cur){
    for(int i:rid) if(f[cur*inv[n]%mod*inv[n-1]%mod*r[i]%mod]){
        g[used].push_back({i,cur});
    }
    for(int i=x;i<=n-2;i++){
        if(used+i>n-2) return;
        dfs_b(i,used+i,cur*iw[n-2][i]%mod);
    }
}

vector<int> dd;
void dfs_ca(int x,int used,int cur){
    for(auto [i,pre]:g[n-2-used]){
        if(cur*n%mod*(n-1)%mod==r[i]*pre%mod && !ans[i]){
            ans[i]=n;
            deg[i]=dd;
            h[n-2-used].push_back({i,pre});
        }
    }
    for(int i=x;i<=min(n-2,6LL);i++){
        if(used+i>n-2) return;
        dd.push_back(i);
        dfs_ca(i,used+i,cur*w[n-2][i]%mod);
        dd.pop_back();
    }
}

void dfs_cb(int x,int used,int cur){
    for(auto [i,pre]:h[used]){
        if(pre==cur){
            for(int d:dd) deg[i].push_back(d);
        }
    }
    for(int i=x;i<=n-2;i++){
        if(used+i>n-2) return;
        dd.push_back(i);
        dfs_cb(i,used+i,cur*iw[n-2][i]%mod);
        dd.pop_back();
    }
}

void solve(){
    build();
    int test;cin >> test;
    for(int i=1;i<=test;i++){
        cin >> r[i];
        if(r[i]==1) ans[i]=1;
        else if(r[i]==2) ans[i]=2;
        else rid.push_back(i);
    }
    for(n=3;n<=N;n++){
        f.reset();
        for(int i=0;i<=n;i++) h[i].clear(),g[i].clear();
        dfs_a(1,0,1);
        dfs_b(7,0,1);
        dfs_ca(1,0,1);
        dfs_cb(7,0,1);
        for(int i=1;i<=test;i++){
            if(ans[i]!=0){
                auto it=find(rid.begin(),rid.end(),i);
                if(it!=rid.end()) rid.erase(it);
            }
        }
        if(rid.empty()) break;
    }

    for(int i=1;i<=test;i++) print(ans[i],deg[i]);
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int test=1;//cin >> test;
    while(test--) solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 78ms
memory: 125860kb

input:

4
2
360
1
509949433

output:

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

result:

ok OK (4 test cases)

Test #2:

score: 0
Accepted
time: 17611ms
memory: 129212kb

input:

9
185396120
468170792
837583517
696626231
338497514
762842660
800028852
928391161
733524004

output:

14
1 5
2 6
3 7
4 8
5 9
6 10
7 11
8 12
9 13
10 13
11 14
12 14
13 14
122
1 97
2 98
3 99
4 100
5 101
6 102
7 103
8 104
9 105
10 106
11 107
12 108
13 109
14 110
15 110
16 111
17 111
18 112
19 112
20 113
21 113
22 113
23 114
24 114
25 114
26 115
27 115
28 115
29 116
30 116
31 116
32 117
33 117
34 117
35 ...

result:

ok OK (9 test cases)

Test #3:

score: 0
Accepted
time: 31340ms
memory: 138900kb

input:

10
338497514
733524004
447182954
415993605
453460670
50499055
648088551
986982752
907925397
315315230

output:

124
1 76
2 77
3 78
4 79
5 80
6 81
7 82
8 83
9 84
10 85
11 86
12 87
13 88
14 89
15 90
16 91
17 92
18 93
19 94
20 95
21 96
22 97
23 98
24 99
25 100
26 101
27 102
28 103
29 104
30 105
31 106
32 107
33 108
34 109
35 110
36 110
37 111
38 111
39 112
40 112
41 113
42 113
43 113
44 113
45 114
46 114
47 114
...

result:

ok OK (10 test cases)

Test #4:

score: 0
Accepted
time: 4173ms
memory: 126060kb

input:

10
1
2
3
4
5
6
7
8
9
10

output:

1
2
1 2
102
1 88
2 89
3 90
4 91
5 91
6 92
7 92
8 93
9 93
10 94
11 94
12 95
13 95
14 96
15 96
16 96
17 96
18 96
19 96
20 97
21 97
22 97
23 97
24 97
25 97
26 97
27 97
28 98
29 98
30 98
31 98
32 98
33 98
34 98
35 98
36 98
37 99
38 99
39 99
40 99
41 99
42 99
43 99
44 99
45 99
46 99
47 100
48 100
49 100
...

result:

ok OK (10 test cases)

Test #5:

score: 0
Accepted
time: 1919ms
memory: 125952kb

input:

10
269199917
392009324
753889928
751355133
472639410
132096559
331333826
40414701
72847302
475706026

output:

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

result:

ok OK (10 test cases)

Extra Test:

score: 0
Extra Test Passed