竞赛讨论区 > 建议需要取模的题目尽量不用优先队列
头像
Cabbaken
发布于 03-19 02:18
+ 关注

建议需要取模的题目尽量不用优先队列

如此题小美的游戏

如果使用优先队列:

#include <bits/stdc++.h>

#define int ll
using ll = long long;

void PPP()
{
#ifndef ONLINE_JUDGE
        freopen("in", "r", stdin);
//	freopen("out","w",stdout);
#endif
}

const int LEN = 2e5 + 7;
const int MOD = 1e9 + 7;

std::priority_queue<int, std::vector<int>, std::less<int>> pq;

void solve()
{
        int n, k;
        std::cin >> n >> k;
        for (int i = 1; i <= n; ++i)
        {
                int t;
                std::cin >> t;
                pq.push(t);
        }
        while (k--)
        {
                int x = pq.top();
                pq.pop();
                int y = pq.top();
                pq.pop();
                x = x * y % MOD;
                y = 1;
                pq.push(x);
                pq.push(y);
        }
        int res = 0;
        while (pq.size())
        {
                res = (res + pq.top()) % MOD;
                pq.pop();
        }

        std::cout << res%MOD;
}


signed main()
{
        //	PPP();
        int T = 1;
        //	std::cin>>T;
        while (T--)
        {
                solve();
        }


        return 0;
}

你将会由于35行的取模得到错误的答案。

全部评论

(0) 回帖
加载中...
话题 回帖

本文相关内容

等你来战

查看全部

热门推荐