QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#116043#4770. Binomial coefficientsmomoyuu#WA 70ms11100kbC++171.9kb2023-06-28 01:44:352023-06-28 01:44:37

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-28 01:44:37]
  • 评测
  • 测评结果:WA
  • 用时:70ms
  • 内存:11100kb
  • [2023-06-28 01:44:35]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

ll comb[1001][1001];
void solve(){
    ll m;
    cin>>m;
    set<pair<ll,ll>> ans;
    ans.insert(make_pair(m,1));
    ans.insert(make_pair(m,m-1));
    for(int i = 1;i<=1000;i++){
        for(int j = 0;j<=1000;j++){
            if(comb[i][j]==m) ans.insert(make_pair(i,j));
        }
    }
    for(ll k = 2;k<=7;k++){
        ll now = 1;
        for(ll i = 1;i<=k;i++) now *= i;
        ll right = 1e9;
        ll left = k;
        while(right-left>1){
            ll mid = (right+left)/2;
            ll kk = 1;
            for(int i = 0;i<k;i++){
                if(kk>m/(k*(mid-i))) {
                    kk = -1;
                    break;
                }
                kk *= mid - i;
            }
            if(kk==-1){
                right = mid;
                continue;
            }
            kk /= now;
            if(kk==m){
                ans.insert(make_pair(mid,k));
                ans.insert(make_pair(mid,mid-k));
            }
            if(kk<=m) left = mid;
            else right = mid;
        }
    }
    cout<<ans.size()<<endl;
    int cnt = 0;
    for(auto&itr:ans){
        if(cnt++) cout<<" ";
        cout<<"("<<itr.first<<","<<itr.second<<")";
    }
    cout<<endl;
        
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    comb[1][0] = comb[1][1] = 1;
    for(int i = 2;i<=1000;i++){
        comb[i][0] = comb[i][i] = 1;
        for(int j = 1;j<i;j++){
            if(comb[i-1][j]==-1) continue;
            if(comb[i-1][j-1]==-1) continue;
            if(comb[i-1][j]+comb[i-1][j-1]>=2e15) {
                comb[i][j] = -1;
                continue;
            }
            comb[i][j] = comb[i-1][j] + comb[i-1][j-1];
        }
    }

    int t;
    cin>>t;
    while(t--){
        solve();
    }
}

详细

Test #1:

score: 100
Accepted
time: 5ms
memory: 10728kb

input:

2
2
15

output:

1
(2,1)
4
(6,2) (6,4) (15,1) (15,14)

result:

ok 4 lines

Test #2:

score: -100
Wrong Answer
time: 70ms
memory: 11100kb

input:

100
2
3
4
5
6
7
8
9
10
15
120
3003
24310
495918532948104
1000000000000000
210
1540
2701
7140
11628
48620
614386
705432
817190
885115
4200651
4610166
5311735
5918520
6299475
6666891
6876486
7023974
7610851
8002000
8948565
9016381
9411291
9695406
30421755
1676056044
9075135300
101766230790
13784652882...

output:

1
(2,1)
2
(3,1) (3,2)
2
(4,1) (4,3)
2
(5,1) (5,4)
3
(4,2) (6,1) (6,5)
2
(7,1) (7,6)
2
(8,1) (8,7)
2
(9,1) (9,8)
4
(5,2) (5,3) (10,1) (10,9)
4
(6,2) (6,4) (15,1) (15,14)
6
(10,3) (10,7) (16,2) (16,14) (120,1) (120,119)
8
(14,6) (14,8) (15,5) (15,10) (78,2) (78,76) (3003,1) (3003,3002)
6
(17,8) (17,9)...

result:

wrong answer 43rd lines differ - expected: '4', found: '2'