QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#685214#9529. Farm ManagementF0givenersWA 0ms3588kbC++203.1kb2024-10-28 18:19:312024-10-28 18:19:31

Judging History

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

  • [2024-10-28 18:19:31]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3588kb
  • [2024-10-28 18:19:31]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ui = unsigned int;
using ull = unsigned long long;
using ll = long long;
#define endl '\n'
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int maxn = 2e5 + 10;
const int mod = 1000000007;
#define inl inline
#define fr(i, a, b) for (int i = a; i <= b; i++)
#define ford(i, a, b) for (int i = a; i >= b; i--)
#define forall(i, a) for (auto &i : a)

/**
   ____         ___ _____
  / ___| _   _ / _ \___ /
  \___ \| | | | | | ||_ \
   ___) | |_| | |_| |__) |
  |____/ \__, |\___/____/
         |___/
*/
istream &operator>>(istream &in, vector<int> &v)
{
    for (auto &i : v)
        in >> i;
    return in;
}
ostream &operator<<(ostream &out, vector<int> &v)
{
    for (auto &i : v)
        out << i << " ";
    return out;
}
bool _output = 0;

#define int ll
int n, s, m;

unordered_map<int, int> mp;
int a[maxn];
int t;
int b[40];
int ans = LLONG_MAX;
int make_cnt = 0;

void make()
{
    make_cnt++;
    map<int, int> mp2;
    auto print = [&]()
    {
        cout << t << " ";
        fr(i, 1, t) cout << b[i] << " ";
        cout << endl;
    };
    // print();
    for (int i = 1; i <= t; i++)
    {
        mp2[b[i]]++;
    }
    int q = 0;
    int sum = 0;
    fr(i, 1, t) sum += b[i];
    int p = s - sum;

    mp2[1] += p;
    int p1 = mp[1];
    q += min(mp2[1], p1);
    for (auto [k, v] : mp2)
    {
        if (k == 1)
            continue;
        q += min(v, mp[k]);
    }
    if (q == 1)
    {
        if (p >= 0)
            ans = min(ans, t + n + p - 2 * q);
    }
    else if (p >= 0)
        ans = min(ans, t + n + p - 2 * q);
    // if (t + n - 2 * q == 4)
    // {
    //     cout << p << endl;
    //     print();
    // }
}
int dfs_cnt = 0;
int qsm(int a, int b)
{
    int res = 1;
    while (b)
    {
        if (b & 1)
            res *= a;
        if (res > 1e15)
            return -1;
        a *= a;
        b >>= 1;
    }
    return res;
}
void dfs(int idx, int m)
{
    ++dfs_cnt;
    // cout << dfs_cnt << endl;
    if (idx == t)
    {
        b[idx] = m;
        make();
        return;
    }
    int l = b[idx - 1];
    if (idx == 1)
        l = 2;
    int r = 1e9;

    // cout << "! " << l << " " << r << endl;
    fr(i, l, r)
    {
        if (qsm(i, t - idx + 1) > m || qsm(i, t - idx + 1) < 0)
            break;
        if (m % i == 0)
        {
            b[idx] = i;
            dfs(idx + 1, m / i);
        }
    }
}

void solve()
{
    // cout << (int)(pow(1000000000, 1.0 / 3)) << endl;
    // return;
    cin >> n >> s >> m;
    fr(i, 1, n)
    {
        cin >> a[i];
        mp[a[i]]++;
    }
    fr(i, 2, 33)
    {
        t = i;
        dfs(1, m);
    }

    t = 1;
    b[1] = m;
    make();

    // cout << dfs_cnt << endl;
    if (ans == LLONG_MAX)
        ans = -1;
    cout << ans << endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int _ = 1;
    if (_output)
        cin >> _;
    while (_--)
        solve();
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3588kb

input:

5 17
2 3 4
6 1 5
8 2 4
4 3 3
7 5 5

output:

19

result:

wrong answer 1st lines differ - expected: '109', found: '19'