QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#417577 | #8723. 乘二 | skip2004 | ML | 0ms | 0kb | Pascal | 1.2kb | 2024-05-22 19:50:11 | 2024-05-22 19:50:11 |
answer
const P = 1000000007;
var n, k, i, rem, tmp : longint;
a : array [1..200000] of longint;
ans, pw : int64;
procedure qsort(l,r:longint);
var i,j,x,y:longint;
begin
i:=l; j:=r; x:=a[(l+r) div 2];
repeat
while (a[i]<x) and (i<j) do inc(i);
while (a[j]>x) and (i<j) do dec(j);
if (i<j) then
begin
y:=a[i];
a[i]:=a[j];
a[j]:=y;
inc(i);
dec(j);
end;
until i>=j;
if (i<r) then qsort(i,r);
if (j>l) then qsort(j,l);
end;
begin
read(n, k);
for i := 1 to n do
read(a[i]);
qsort(1, n);
while (a[1] < P) and (k > 0) do
begin
tmp := a[1] * 2;
for i := 2 to n do
if a[i-1] > a[i] then
begin
writeln(-1);
halt;
end;
for i := 1 to n do
begin
if (k = 0) or (a[i] > tmp) then
break;
a[i] := a[i] * 2;
dec(k);
end;
qsort(1, n);
end;
pw := 1;
rem := k mod n;
k := k div n;
while k > 30 do
begin
pw := (pw << 30) mod P;
k := k - 30;
end;
for i := 1 to k do
pw := pw * 2 mod P;
for i := 1 to rem do
ans := (ans + a[i] * pw * 2) mod P;
for i := rem + 1 to n do
ans := (ans + a[i] * pw) mod P;
writeln(ans);
end.
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Memory Limit Exceeded
input:
3 3 7 2 1