QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#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.
詳細信息
Test #1:
score: 0
Memory Limit Exceeded
input:
3 3 7 2 1