QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#739130#9738. Make It Divisibleqianchen06WA 1ms3600kbC++142.6kb2024-11-12 20:57:372024-11-12 20:57:38

Judging History

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

  • [2024-11-27 18:44:44]
  • hack成功,自动添加数据
  • (/hack/1263)
  • [2024-11-14 09:10:13]
  • hack成功,自动添加数据
  • (/hack/1178)
  • [2024-11-12 20:57:38]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3600kb
  • [2024-11-12 20:57:37]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 1e5 + 10;

int n, k;
int b[maxn];
int a[maxn];
void solve()
{
    cin >> n >> k;
    map<int, int> mp;
    for (int i = 1; i <= n; i++)
    {
        cin >> b[i];
        a[i] = b[i];
    }
    set<int> st;
    int sum = 0;
    if (n == 1)
    {
        cout << k << ' ';
        cout << (1ll + k) * k / 2ll << '\n';
        return;
    }
    for (int i = 1; i < n; i++)
    {
        int r = a[i + 1];
        int l = a[i];
        if (l > r)
            swap(l, r);
        int kx = r / l;

        if (l == 1)
        {
            int y = r - l;
            for (int j = 1; j * j <= y; j++)
            {
                if (y % j == 0)
                {
                    if (j == 1)
                    {
                    }
                    else
                    {
                        if ((j - 1) <= k && (r + j - 1) % (l + j - 1) == 0)
                        {
                            st.insert(j - 1);
                            sum += j - 1;
                        }
                    }
                }
                if (y % j == 0 && j * j != y)
                {
                    int le = y / j;
                    if (le == 1)
                    {
                    }
                    else
                    {
                        if ((le - 1) <= k && (r + le - 1) % (l + le - 1) == 0)
                        {
                            st.insert(le - 1);
                            sum += le - 1;
                        }
                    }
                }
            }
        }
        else
        {
            set<int> stt;
            sum = 0;
            for (int j = kx; j >= 2; j--)
            {
                int les = r - l * j;
                if (les <= 0)
                    continue;
                if (les % (j - 1) != 0)
                    continue;
                int y = les / (j - 1);
                if (y <= k && (st.count(y) || i == 1))
                {
                    stt.insert(y);
                    sum += (y);
                }
            }
            swap(stt, st);
        }
    }
    if (st.count(0))
        st.erase(0);
    while (st.upper_bound(k) != st.end())
    {
        sum -= *st.rbegin();
        st.erase(--st.end());
    }
    cout << st.size() << ' ';

    cout << sum << '\n';
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3600kb

input:

3
5 10
7 79 1 7 1
2 1000000000
1 2
1 100
1000000000

output:

3 32
0 0
100 5050

result:

wrong answer 1st lines differ - expected: '3 8', found: '3 32'