Submission #2559931
Source Code Expand
#include <iostream>
#include <algorithm>
#include <utility>
#include <climits>
using namespace std;
typedef long long ll;
const ll INF = LLONG_MAX;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
const ll siz = 200;
ll n, x, a[4002], cnt[2002]{}, xmax = 0, bucket[siz];
void init() {
fill(bucket, bucket + siz, INF);
REP(i, n * 2) { bucket[i / siz] = min(bucket[i / siz], a[i]); }
}
//[l,r)
ll rmq(ll l, ll r) {
ll res = INF;
REP(i, siz) {
if ((i + 1) * siz < l || i * siz >= r) continue;
if (i * siz >= l && (i + 1) * siz < r) {
res = min(res, bucket[i]);
} else {
FOR(j, max(l, i * siz), min(r, (i + 1) * siz)) {
res = min(res, a[j]);
}
}
}
return res;
}
int main() {
cin >> n >> x;
REP(i, n) {
cin >> a[i];
a[i + n] = a[i]; // n->1のループをしやすくする
}
init();
ll ans = INF;
REP(t, n) {
ll asum = 0;
FOR(i, n, n * 2) { asum += rmq(i - t, i + 1); }
ans = min(ans, asum + x * t);
}
cout << ans << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
B - Colorful Slimes |
User |
NOSS |
Language |
C++14 (GCC 5.4.1) |
Score |
400 |
Code Size |
1264 Byte |
Status |
AC |
Exec Time |
1605 ms |
Memory |
384 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
400 / 400 |
Status |
|
|
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 |
1603 ms |
256 KB |
1_01.txt |
AC |
1604 ms |
256 KB |
1_02.txt |
AC |
1605 ms |
256 KB |
1_03.txt |
AC |
1604 ms |
256 KB |
1_04.txt |
AC |
1605 ms |
256 KB |
1_05.txt |
AC |
1604 ms |
256 KB |
1_06.txt |
AC |
1604 ms |
256 KB |
1_07.txt |
AC |
1604 ms |
256 KB |
1_08.txt |
AC |
1604 ms |
256 KB |
1_09.txt |
AC |
1605 ms |
256 KB |
1_10.txt |
AC |
1172 ms |
256 KB |
1_11.txt |
AC |
1569 ms |
256 KB |
1_12.txt |
AC |
1443 ms |
384 KB |
1_13.txt |
AC |
977 ms |
256 KB |
1_14.txt |
AC |
1563 ms |
256 KB |
1_15.txt |
AC |
1206 ms |
256 KB |
1_16.txt |
AC |
1387 ms |
256 KB |
1_17.txt |
AC |
1578 ms |
256 KB |