Submission #1503403


Source Code Expand

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto X = s[1].to!long;
    auto A = readln.split.map!(to!long).array;
    
    auto mins = new long[][](N, N);
    foreach (i; 0..N) fill(mins[i], 1L << 59);

    foreach (i; 0..N) {
        mins[i][0] = A[i];
        foreach (jj; 1..N) {
            int j = (i - jj + N) % N;
            mins[i][jj] = min(mins[i][jj-1], A[j]);
        }
    }

    long ans = 1L << 59;
    foreach (i; 0..N) {
        long tmp = 0;
        foreach (j; 0..N) tmp += mins[j][i];
        ans = min(ans, tmp + i * X);
    }

    ans.writeln;
}

Submission Info

Submission Time
Task B - Colorful Slimes
User nebukuro09
Language D (LDC 0.17.0)
Score 400
Code Size 812 Byte
Status AC
Exec Time 62 ms
Memory 34428 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 21
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt
Case Name Status Exec Time Memory
0_00.txt AC 1 ms 256 KB
0_01.txt AC 1 ms 256 KB
0_02.txt AC 1 ms 256 KB
1_00.txt AC 60 ms 34044 KB
1_01.txt AC 60 ms 34172 KB
1_02.txt AC 61 ms 33532 KB
1_03.txt AC 62 ms 33532 KB
1_04.txt AC 61 ms 34300 KB
1_05.txt AC 61 ms 33276 KB
1_06.txt AC 61 ms 33532 KB
1_07.txt AC 61 ms 33404 KB
1_08.txt AC 60 ms 34428 KB
1_09.txt AC 60 ms 32636 KB
1_10.txt AC 40 ms 29820 KB
1_11.txt AC 59 ms 32124 KB
1_12.txt AC 54 ms 32764 KB
1_13.txt AC 33 ms 27132 KB
1_14.txt AC 58 ms 32764 KB
1_15.txt AC 41 ms 29820 KB
1_16.txt AC 51 ms 30332 KB
1_17.txt AC 60 ms 32636 KB