QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#686237 | #8723. 乘二 | Xwc | WA | 64ms | 12176kb | C++14 | 1.9kb | 2024-10-29 09:23:44 | 2024-10-29 09:23:46 |
Judging History
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], c[n] = 0;
for(int i = n - 1; i >= 1; i -- ) {
ll x = a[i], cnt = 0;
if(a[i] == a[i + 1]) {
mx[i] = mx[i + 1];
c[i] = c[i + 1];
} else {
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], 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) % mod;
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 % mod << '\n';
// cout << 100 * qpow(2, 100) % mod;
// for(int i = 1; i <= n; i ++ ) {
// cout << a[i] << ' ';
// }
}
int main()
{
// fastio;
int t = 1;
// cin >> t;
while( t -- ) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5636kb
input:
3 3 7 2 1
output:
15
result:
ok 1 number(s): "15"
Test #2:
score: -100
Wrong Answer
time: 64ms
memory: 12176kb
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'