本地编译没问题,但提交洛谷时编译错误
查看原帖
本地编译没问题,但提交洛谷时编译错误
482592
minVan楼主2023/5/31 12:03
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 10;
struct node {
    int k, p;
} a[N];
int n, m, ans, tot1 = 0, tot2 = 0;
map<int, int> mp1, mp2;
inline int pow(int a, int x) {
    int s = 1, tmp = x;
    while(x--) {
        s *= a;
    }
    return s;
}
inline bool cmp(int x, int y) {
    return x > y;
}
inline void dfs1(int x, int sum) {
    if(x > n / 2) {
        mp1[++tot1] = sum;
        return ;
    }
    for(int i = 1; i <= m; i++) {
        dfs1(x + 1, sum + a[x].k * pow(i, a[x].p));
    }
}
inline void dfs2(int x, int sum) {
    if(x > n) {
        mp2[++tot2] = sum;
        return ;
    }
    for(int i = 1; i <= m; i++) {
        dfs2(x + 1, sum + a[x].k * pow(i, a[x].p));
    }
}
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        cin >> a[i].k >> a[i].p;
    }
    dfs1(1, 0);
    dfs2(n / 2 + 1, 0);
    sort(mp1.begin(), mp1.end());
    sort(mp2.begin(), mp2.end(), cmp);
    for(int i = 1, j = tot2; i <= tot1 && j >= 1; ) {
        int k = i, kk = j;
        while(mp1[i] == mp1[k] && i <= tot1 + 1) {
            ++i;
        }
        while(mp2[j] == -mp1[k] && j >= 0) {
            --j;
        }
        ans += ((i - k) * (kk - j));
    }
    cout << ans;
    return 0;
}

评测记录

2023/5/31 12:03
加载中...