QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#686226#8723. 乘二XwcWA 62ms12656kbC++141.7kb2024-10-29 09:08:032024-10-29 09:08:04

Judging History

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

  • [2024-10-29 09:08:04]
  • 评测
  • 测评结果:WA
  • 用时:62ms
  • 内存:12656kb
  • [2024-10-29 09:08:03]
  • 提交

answer

#include <bits/stdc++.h>

#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

typedef double ff;
typedef long long int ll;
typedef unsigned long long int ull;
typedef __int128 i128;
using namespace std;

typedef pair<ll, ll> pii;

const int N = 2e5 + 10, M = 1e7, mod = 1e9 + 7;

ll a[N], mx[N], c[N], n, k;

ll qpow(ll a, ll k)
{
	ll res = 1;
	while( k ) {
		if(k & 1) res = res * a % mod;
		k = k >> 1;
		a = a * a % mod;
	}
	return res;
}

void solve()
{
	cin >> n >> k;
	
	for(int i = 1; i <= n; i ++ ) cin >> a[i];
	
	sort(a + 1, a + 1 + n);
	
	mx[n] = a[n];
	for(int i = n - 1; i >= 1; i -- ) {
		ll x = a[i], cnt = 0;
		while(x * 2 <= mx[i + 1]) {
			x *= 2;
			cnt ++;
		}
		mx[i] = x;
		c[i] = cnt;
	}
	
	// for(int i = 1; i <= n; i ++ ) {
		// cout << a[i] << ' ' << mx[i] << ' ' << c[i] << '\n';
	// }
	priority_queue<pii, vector<pii>, greater<pii> > q;
	for(int i = 1; i <= n; i ++ ) {
		q.push({a[i], i});
	}
	
	while(k && q.size()) {
		auto t = q.top();
		q.pop();
		
		if(c[t.second] == 0) continue;
		
		a[t.second] *= 2;
		c[t.second] -= 1;
		k --;
		q.push({a[t.second], c[t.second]});
	}
	
	ll sum = 0;
	for(int i = 1; i <= n; i ++ ) {
		// cout << a[i] << ' ';
		sum = (sum + a[i]) % mod;
 	}
	
	if( k ) {
		ll r = k / n, ex = k % n;
		
		sum = sum * qpow(2, r);
		
		for(int i = 1; i <= ex; i ++ ) {
			ll tmp = a[i] * qpow(2, r) % mod;
			sum = ((sum - tmp) % mod + mod) % mod;
			tmp = tmp * 2 % mod;
			sum = (sum + tmp) % mod;
		}
	}
	
	cout << sum << '\n';
	
	// for(int i = 1; i <= n; i ++ ) {
		// cout << a[i] << ' ';
	// }
}


int main()
{
	// fastio;
	
	int t = 1;
	// cin >> t;

	while( t -- ) solve();
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5584kb

input:

3 3
7 2 1

output:

15

result:

ok 1 number(s): "15"

Test #2:

score: -100
Wrong Answer
time: 62ms
memory: 12656kb

input:

200000 1605067
366760624 67854 93901 693975 27016 1046 10808 6533158 54778 500941023 77236442 32173 10431454 2 9726 1553148 89282 411182309 494073 131299543 249904771 7906930 353 9909 3632698 29156 1917186 303 737 1189004 22 1983 263 711 4106258 2070 36704 12524642 5192 123 2061 22887 66 380 1 10153...

output:

33299264

result:

wrong answer 1st numbers differ - expected: '707034173', found: '33299264'