QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#232143#7613. Inverse ProblemCharlieVinnieTL 21602ms208548kbC++172.8kb2023-10-29 22:15:332023-10-29 22:15:34

Judging History

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

  • [2023-10-29 22:15:34]
  • 评测
  • 测评结果:TL
  • 用时:21602ms
  • 内存:208548kb
  • [2023-10-29 22:15:33]
  • 提交

answer

#include "bits/stdc++.h"
#ifdef DEBUG
#include "PrettyDebug.hpp"
#else
#define debug(...) [](auto...){}(__VA_ARGS__)
#define debuga(...) [](auto...){}(__VA_ARGS__)
#endif
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(int i=a;i>=b;i--)
#define Fin(file) freopen(file,"r",stdin)
#define Fout(file) freopen(file,"w",stdout)
#define assume(expr) ((!!(expr))||(exit((fprintf(stderr,"Assumption Failed: %s on Line %d\n",#expr,__LINE__),-1)),false))
#define range basic_string_view
using namespace std; typedef long long ll;
constexpr int mod=1e9+7,B=6;
inline int qpow(int x,int y){int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
bitset<mod> vis; int val[205],ival[205]; vector<int> lis[205],lis2[205];
bool solve(int o,int n){
    o=1ll*o*qpow(n,mod-2)%mod*qpow(n-1,mod-2)%mod;
    debug(o,n);
    for(int i=0,t=1;i<=n-2;i++) val[i]=t,t=1ll*t*(n-2-i)%mod;
    For(i,0,n-2) ival[i]=qpow(val[i],mod-2);
    For(i,0,n-2) lis[i].clear(),lis2[i].clear();
    function<void(int,int,int)> dfs1=[&](int d,int tot,int x){
        lis[tot].push_back(x);
        For(i,d,min(B,n-2-tot)) dfs1(i,tot+i,1ll*x*ival[i]%mod);
    };
    function<void(int,int,int)> dfs2=[&](int d,int tot,int x){
        lis2[tot].push_back(x);
        For(i,d,n-2-tot) dfs2(i,tot+i,1ll*x*val[i]%mod);
    };
    dfs1(1,0,o); dfs2(B+1,0,1);
    For(s,0,n-2){
        for(int x:lis[s]) vis.set(x);
        int X=0;
        for(int x:lis2[n-2-s]) if(vis.test(x)) { X=x; break; }
        for(int x:lis[s]) vis.reset(x);
        if(!X) continue;
        vector<int> ans;
        function<bool(int,int,int)> dfs3=[&](int d,int tot,int x){
            if(tot==s&&x==X) return true;
            For(i,d,min(B,n-2-tot)){
                ans.push_back(i); if(dfs3(i,tot+i,1ll*x*ival[i]%mod)) return true; else ans.pop_back();
            }
            return false;
        };
        function<bool(int,int,int)> dfs4=[&](int d,int tot,int x){
            if(tot==n-2-s&&x==X) return true;
            For(i,d,n-2-tot){
                ans.push_back(i); if(dfs4(i,tot+i,1ll*x*val[i]%mod)) return true; else ans.pop_back();
            }
            return false;
        };
        assert(dfs3(1,0,o)); assert(dfs4(B+1,0,1));
        ans.resize(n); debug(ans);
        cout<<n<<'\n';
        for(int i=1,p=2;i<=n;i++){
            For(_,1,ans[i-1]+(i==1)) cout<<i<<' '<<p++<<'\n';
        }
        return true;
    }
    return false;
}
signed main(){
    atexit([](){cerr<<"Time = "<<clock()<<" ms"<<endl;});
    int T; cin>>T; while(T--) { int o; cin>>o; if(o==1) { cout<<1<<'\n'; continue; }; int n=2; while(!solve(o,n)) n++; }
    return 0;
}

// START TYPING IF YOU DON'T KNOW WHAT TO DO
// STOP TYPING IF YOU DON'T KNOW WHAT YOU'RE DOING
// CONTINUE, NON-STOPPING, FOR CHARLIEVINNIE

// Started Coding On: October 28 Sat, 07 : 43 : 27

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 120252kb

input:

4
2
360
1
509949433

output:

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

result:

ok OK (4 test cases)

Test #2:

score: 0
Accepted
time: 21602ms
memory: 208548kb

input:

9
185396120
468170792
837583517
696626231
338497514
762842660
800028852
928391161
733524004

output:

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

result:

ok OK (9 test cases)

Test #3:

score: -100
Time Limit Exceeded

input:

10
338497514
733524004
447182954
415993605
453460670
50499055
648088551
986982752
907925397
315315230

output:

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

result: