Submission #1227627
Source Code Expand
/+ dub.sdl:
name "A"
dependency "dcomp" version=">=0.6.0"
+/
import std.stdio, std.algorithm, std.range, std.conv;
import std.typecons;
import std.bigint;
// import dcomp.foundation, dcomp.scanner;
int main() {
auto sc = new Scanner(stdin);
long n, m, k;
sc.read(n, m, k); m++;
long[] a;
sc.read(a);
long[] dp = a.dup;
long[] ndp = new long[n];
foreach (ph; 2..k+1) {
ndp[] = 0;
foreach (i; 0..n) {
foreach (j; 1..m) {
if (i-j < 0) continue;
ndp[i] = max(ndp[i], dp[i-j] + ph * a[i]);
}
}
dp[] = ndp[];
}
writeln(dp.fold!max);
return 0;
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */
// module dcomp.foundation;
//fold(for old compiler)
static if (__VERSION__ <= 2070) {
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
import std.algorithm : reduce;
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
import std.typecons : tuple;
return reduce!fun(tuple(seed), r);
}
}
}
unittest {
import std.stdio;
auto l = [1, 2, 3, 4, 5];
assert(l.fold!"a+b"(10) == 25);
}
}
version (X86) static if (__VERSION__ < 2071) {
int bsf(ulong v) {
foreach (i; 0..64) {
if (v & (1UL << i)) return i;
}
return -1;
}
int bsr(ulong v) {
foreach_reverse (i; 0..64) {
if (v & (1UL << i)) return i;
}
return -1;
}
int popcnt(ulong v) {
int c = 0;
foreach (i; 0..64) {
if (v & (1UL << i)) c++;
}
return c;
}
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;
class Scanner {
import std.stdio : File;
import std.conv : to;
import std.range : front, popFront, array, ElementType;
import std.array : split;
import std.traits : isSomeChar, isStaticArray, isArray;
import std.algorithm : map;
File f;
this(File f) {
this.f = f;
}
char[512] lineBuf;
char[] line;
private bool succ() {
import std.range.primitives : empty, front, popFront;
import std.ascii : isWhite;
while (true) {
while (!line.empty && line.front.isWhite) {
line.popFront;
}
if (!line.empty) break;
if (f.eof) return false;
line = lineBuf[];
f.readln(line);
}
return true;
}
private bool readSingle(T)(ref T x) {
import std.algorithm : findSplitBefore;
import std.string : strip;
import std.conv : parse;
if (!succ()) return false;
static if (isArray!T) {
alias E = ElementType!T;
static if (isSomeChar!E) {
//string or char[10] etc
//todo optimize
auto r = line.findSplitBefore(" ");
x = r[0].strip.dup;
line = r[1];
} else {
auto buf = line.split.map!(to!E).array;
static if (isStaticArray!T) {
//static
assert(buf.length == T.length);
}
x = buf;
line.length = 0;
}
} else {
x = line.parse!T;
}
return true;
}
int read(T, Args...)(ref T x, auto ref Args args) {
if (!readSingle(x)) return 0;
static if (args.length == 0) {
return 1;
} else {
return 1 + read(args);
}
}
}
unittest {
import std.path : buildPath;
import std.file : tempDir;
import std.algorithm : equal;
import std.stdio : File;
string fileName = buildPath(tempDir, "kyuridenanmaida.txt");
auto fout = File(fileName, "w");
fout.writeln("1 2 3");
fout.writeln("ab cde");
fout.writeln("1.0 1.0 2.0");
fout.close;
Scanner sc = new Scanner(File(fileName, "r"));
int a;
int[2] b;
char[2] c;
string d;
double e;
double[] f;
sc.read(a, b, c, d, e, f);
assert(a == 1);
assert(equal(b[], [2, 3]));
assert(equal(c[], "ab"));
assert(equal(d, "cde"));
assert(e == 1.0);
assert(equal(f, [1.0, 2.0]));
}
unittest {
import std.path : buildPath;
import std.file : tempDir;
import std.algorithm : equal;
import std.stdio : File, writeln;
import std.datetime;
string fileName = buildPath(tempDir, "kyuridenanmaida.txt");
auto fout = File(fileName, "w");
foreach (i; 0..1_000_000) {
fout.writeln(3*i, " ", 3*i+1, " ", 3*i+2);
}
fout.close;
writeln("Scanner Speed Test(3*1,000,000 int)");
StopWatch sw;
sw.start;
Scanner sc = new Scanner(File(fileName, "r"));
foreach (i; 0..500_000) {
int a, b, c;
sc.read(a, b, c);
assert(a == 3*i);
assert(b == 3*i+1);
assert(c == 3*i+2);
}
foreach (i; 500_000..700_000) {
int[3] d;
sc.read(d);
int a = d[0], b = d[1], c = d[2];
assert(a == 3*i);
assert(b == 3*i+1);
assert(c == 3*i+2);
}
foreach (i; 700_000..1_000_000) {
int[] d;
sc.read(d);
assert(d.length == 3);
int a = d[0], b = d[1], c = d[2];
assert(a == 3*i);
assert(b == 3*i+1);
assert(c == 3*i+2);
}
writeln(sw.peek.msecs, "ms");
}
Submission Info
Submission Time |
|
Task |
A - Struck Out |
User |
yosupo |
Language |
D (LDC 0.17.0) |
Score |
0 |
Code Size |
5793 Byte |
Status |
WA |
Exec Time |
2107 ms |
Memory |
8760 KB |
Judge Result
Set Name |
Sample |
subtask1 |
subtask2 |
subtask3 |
All |
Score / Max Score |
0 / 0 |
0 / 100 |
0 / 200 |
0 / 300 |
0 / 100 |
Status |
|
|
|
|
|
Set Name |
Test Cases |
Sample |
sample_1.txt, sample_2.txt, sample_3.txt |
subtask1 |
sample_2.txt, subtask_1_1.txt, subtask_1_2.txt, subtask_1_3.txt, subtask_1_4.txt, subtask_1_5.txt, subtask_1_6.txt, subtask_1_7.txt, subtask_1_8.txt, subtask_1_9.txt |
subtask2 |
sample_1.txt, sample_2.txt, sample_3.txt, subtask_2_1.txt, subtask_2_2.txt, subtask_2_3.txt, subtask_2_4.txt, subtask_2_5.txt, subtask_2_6.txt, subtask_2_7.txt, subtask_2_8.txt, subtask_2_9.txt |
subtask3 |
sample_1.txt, sample_2.txt, sample_3.txt, subtask_2_1.txt, subtask_2_2.txt, subtask_2_3.txt, subtask_2_4.txt, subtask_2_5.txt, subtask_2_6.txt, subtask_2_7.txt, subtask_2_8.txt, subtask_2_9.txt, subtask_3_1.txt, subtask_3_2.txt, subtask_3_3.txt, subtask_3_4.txt, subtask_3_5.txt, subtask_3_6.txt, subtask_3_7.txt, subtask_3_8.txt, subtask_3_9.txt |
All |
sample_1.txt, sample_2.txt, sample_3.txt, sample_1.txt, sample_2.txt, sample_3.txt, subtask_1_1.txt, subtask_1_2.txt, subtask_1_3.txt, subtask_1_4.txt, subtask_1_5.txt, subtask_1_6.txt, subtask_1_7.txt, subtask_1_8.txt, subtask_1_9.txt, subtask_2_1.txt, subtask_2_2.txt, subtask_2_3.txt, subtask_2_4.txt, subtask_2_5.txt, subtask_2_6.txt, subtask_2_7.txt, subtask_2_8.txt, subtask_2_9.txt, subtask_3_1.txt, subtask_3_2.txt, subtask_3_3.txt, subtask_3_4.txt, subtask_3_5.txt, subtask_3_6.txt, subtask_3_7.txt, subtask_3_8.txt, subtask_3_9.txt, subtask_4_1.txt, subtask_4_10.txt, subtask_4_11.txt, subtask_4_12.txt, subtask_4_13.txt, subtask_4_2.txt, subtask_4_3.txt, subtask_4_4.txt, subtask_4_5.txt, subtask_4_6.txt, subtask_4_7.txt, subtask_4_8.txt, subtask_4_9.txt |
Case Name |
Status |
Exec Time |
Memory |
sample_1.txt |
AC |
1 ms |
256 KB |
sample_2.txt |
AC |
4 ms |
256 KB |
sample_3.txt |
AC |
1 ms |
256 KB |
subtask_1_1.txt |
AC |
2 ms |
256 KB |
subtask_1_2.txt |
TLE |
2103 ms |
2812 KB |
subtask_1_3.txt |
TLE |
2103 ms |
7480 KB |
subtask_1_4.txt |
AC |
1271 ms |
636 KB |
subtask_1_5.txt |
TLE |
2103 ms |
5432 KB |
subtask_1_6.txt |
WA |
15 ms |
256 KB |
subtask_1_7.txt |
TLE |
2103 ms |
6072 KB |
subtask_1_8.txt |
TLE |
2103 ms |
5432 KB |
subtask_1_9.txt |
WA |
125 ms |
380 KB |
subtask_2_1.txt |
AC |
5 ms |
328 KB |
subtask_2_2.txt |
AC |
1 ms |
256 KB |
subtask_2_3.txt |
AC |
2 ms |
256 KB |
subtask_2_4.txt |
AC |
3 ms |
256 KB |
subtask_2_5.txt |
WA |
1 ms |
256 KB |
subtask_2_6.txt |
WA |
1 ms |
256 KB |
subtask_2_7.txt |
AC |
2 ms |
256 KB |
subtask_2_8.txt |
AC |
4 ms |
256 KB |
subtask_2_9.txt |
AC |
3 ms |
328 KB |
subtask_3_1.txt |
TLE |
2103 ms |
7096 KB |
subtask_3_2.txt |
TLE |
2103 ms |
5432 KB |
subtask_3_3.txt |
TLE |
2103 ms |
5432 KB |
subtask_3_4.txt |
TLE |
2103 ms |
3832 KB |
subtask_3_5.txt |
AC |
1184 ms |
636 KB |
subtask_3_6.txt |
AC |
514 ms |
5432 KB |
subtask_3_7.txt |
TLE |
2103 ms |
6840 KB |
subtask_3_8.txt |
AC |
1551 ms |
892 KB |
subtask_3_9.txt |
AC |
959 ms |
5432 KB |
subtask_4_1.txt |
TLE |
2103 ms |
8760 KB |
subtask_4_10.txt |
AC |
146 ms |
6072 KB |
subtask_4_11.txt |
AC |
745 ms |
5944 KB |
subtask_4_12.txt |
AC |
1517 ms |
7352 KB |
subtask_4_13.txt |
TLE |
2107 ms |
5944 KB |
subtask_4_2.txt |
TLE |
2103 ms |
5432 KB |
subtask_4_3.txt |
TLE |
2103 ms |
6712 KB |
subtask_4_4.txt |
TLE |
2103 ms |
7608 KB |
subtask_4_5.txt |
TLE |
2103 ms |
6200 KB |
subtask_4_6.txt |
TLE |
2103 ms |
7096 KB |
subtask_4_7.txt |
TLE |
2103 ms |
7224 KB |
subtask_4_8.txt |
TLE |
2103 ms |
6084 KB |
subtask_4_9.txt |
TLE |
2103 ms |
5944 KB |