QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#224902 | #7613. Inverse Problem | ucup-team004# | AC ✓ | 30521ms | 13432kb | C++20 | 3.5kb | 2023-10-23 17:14:00 | 2023-10-23 17:14:00 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1000000007;
int ksm(ll a,int b,int c=1){
for(;b;b/=2,a=a*a%mod)
if(b&1)c=c*a%mod;
return c;
}
const int N=210;
vector<pair<int,int> >res;
int a[N];
int g[N],ig[N];
int last_ans;
const int B=5;
vector<int>resL_list,resR_list;
int ans_flag;
bool dfsL(int s,int x,int f,int n,int l){
if(s==0){
if(ans_flag){
if(f!=ans_flag)
return 0;
for(int i=1;i<x;++i)
res.emplace_back(a[i]+1,res.size()+1);
return 1;
}else{
resL_list.push_back(f);
return 0;
}
}
for(int i=min(s,l);i>=1;--i){
a[x]=i;
if(dfsL(s-i,x+1,(ll)f*ig[i]%mod,n,i))
return 1;
}
return 0;
}
bool dfsR(int s,int x,int f,int n,int l){
if(s==0){
if(ans_flag){
if(f!=ans_flag)
return 0;
for(int i=1;i<x;++i)
res.emplace_back(a[i]+1,res.size()+1);
return 1;
}else{
resR_list.push_back(f);
return 0;
}
}
for(int i=l;i<=s;++i){
a[x]=i;
if(dfsR(s-i,x+1,(ll)f*g[i]%mod,n,i))
return 1;
}
return 0;
}
vector<pair<int,int> >res_list[N];
vector<pair<int,int> >x_list;
void output(vector<pair<int,int> >res){
int n=res.size();
// for(auto i:res)
// cout<<i.first<<' '<<i.second<<"!\n";
cout<<n<<"\n";
for(;;){
if(res.size()<=1)
return;
sort(res.begin(),res.end());
reverse(res.begin(),res.end());
cout<<res[0].second<<' '<<res[res.size()-1].second<<'\n';
res[0].first--;
res.pop_back();
}
}
void solve(){
if(x_list.empty())
return;
for(int i=2;;++i){
assert(i<N);
int iv=ksm(i*(i-1),mod-2);
g[0]=1;
for(int j=1;j<=i;++j)
g[j]=(ll)g[j-1]*(i-j-1)%mod;
for(int j=0;j<=i;++j)
ig[j]=ksm(g[j],mod-2);
for(int j=0;j<=i-2;++j){
ans_flag=0;
resL_list.clear();
resR_list.clear();
dfsL(j,1,1,i,B);
dfsR(i-2-j,1,1,i,B+1);
sort(resR_list.begin(),resR_list.end());
for(int k:resL_list){
for(int x=0;x<(int)x_list.size();++x){
int rx=(ll)iv*x_list[x].first%mod;
int u=(ll)k*rx%mod;
auto it=lower_bound(resR_list.begin(),resR_list.end(),u);
if(it!=resR_list.end()&&*it==u){
res.clear();
ans_flag=k;
dfsL(j,1,1,i,B);
ans_flag=u;
dfsR(i-2-j,1,1,i,B+1);
while(res.size()<i)
res.emplace_back(0,res.size()+1);
res_list[x_list[x].second]=res;
x_list.erase(x_list.begin()+x);
--x;
}
}
if(x_list.empty())
return;
}
}
}
}
int T;
int main(){
ios::sync_with_stdio(0);cin.tie(0);
cin>>T;
for(int i=1;i<=T;++i){
int x;cin>>x;
if(x!=1)
x_list.emplace_back(x,i);
else
res_list[i].emplace_back(0,1);
}
solve();
for(int i=1;i<=T;++i)
output(res_list[i]);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3504kb
input:
4 2 360 1 509949433
output:
2 2 1 5 1 3 2 4 1 5 2 1 1 10 8 9 7 10 6 7 5 6 4 5 3 4 2 3 1 2 8 1
result:
ok OK (4 test cases)
Test #2:
score: 0
Accepted
time: 25410ms
memory: 13432kb
input:
9 185396120 468170792 837583517 696626231 338497514 762842660 800028852 928391161 733524004
output:
14 2 11 1 12 10 13 9 14 8 9 7 8 6 7 5 6 4 5 3 4 2 3 1 2 10 1 122 20 21 20 22 20 23 20 24 20 25 20 26 20 27 20 28 20 29 20 30 20 31 20 32 20 33 20 34 20 35 20 36 19 37 18 38 20 39 19 40 18 41 17 42 20 43 19 44 18 45 17 46 20 47 19 48 18 49 17 50 20 51 19 52 18 53 17 54 16 55 20 56 19 57 18 58 17 59 1...
result:
ok OK (9 test cases)
Test #3:
score: 0
Accepted
time: 30521ms
memory: 12420kb
input:
10 338497514 733524004 447182954 415993605 453460670 50499055 648088551 986982752 907925397 315315230
output:
124 22 23 22 24 22 25 22 26 22 27 22 28 22 29 22 30 22 31 22 32 22 33 22 34 22 35 22 36 22 37 22 38 22 39 22 40 22 41 22 42 21 43 22 44 21 45 22 46 21 47 22 48 21 49 22 50 21 51 22 52 21 53 22 54 21 55 20 56 19 57 22 58 21 59 20 60 19 61 18 62 22 63 21 64 20 65 19 66 18 67 17 68 16 69 15 70 22 71 21...
result:
ok OK (10 test cases)
Test #4:
score: 0
Accepted
time: 5081ms
memory: 4432kb
input:
10 1 2 3 4 5 6 7 8 9 10
output:
1 2 2 1 102 15 16 15 17 15 18 15 19 15 20 15 21 14 22 15 23 14 24 15 25 14 26 15 27 14 28 15 29 14 30 15 31 14 32 13 33 15 34 14 35 13 36 15 37 14 38 13 39 15 40 14 41 13 42 12 43 15 44 14 45 13 46 12 47 11 48 15 49 14 50 13 51 12 52 11 53 10 54 15 55 14 56 13 57 12 58 11 59 10 60 15 61 14 62 13 63 ...
result:
ok OK (10 test cases)
Test #5:
score: 0
Accepted
time: 1569ms
memory: 3940kb
input:
10 269199917 392009324 753889928 751355133 472639410 132096559 331333826 40414701 72847302 475706026
output:
55 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 84 35 36 35 37 35 38 11 39 10 40 9 ...
result:
ok OK (10 test cases)
Extra Test:
score: 0
Extra Test Passed