Submission #26015768
Source Code Expand
/*
Author : SharpnessV
Right Output ! & Accepted !
*/
#include<bits/stdc++.h>
//#include<atcoder/all>
//#define int long long
#define rep(i, a, b) for(int i = (a);i <= (b);i++)
#define pre(i, a, b) for(int i = (a);i >= (b);i--)
#define rp(i, a) for(int i = 1; i <= (a); i++)
#define pr(i, a) for(int i = (a); i >= 1; i--)
#define go(i, x) for(auto i : x)
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ze(p) memset(p, 0, sizeof(p))
#define mem(p, x) memset(p, x, sizeof(p))
#define YES puts("YES")
#define NO puts("NO")
#define Yes puts("Yes")
#define No puts("No")
#define si(x) (int)(x).size()
#define db cerr
#define pc putchar
#define gc getchar
#define el putchar('\n')
using namespace std;
const double eps = 1e-15, pi = 3.1415926535897932385;
typedef long long LL;
typedef pair<int,int> Pr;
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}, inf = 0x7fffffff;
//Author : SharpnessV
//#define main Solution
//char buf[1<<22],*p1=buf,*p2=buf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline int read() {
int x = 0;
bool f = 1;
char ch = gc();
while(!isdigit(ch))f = ('-' == ch ? 0 : 1), ch = gc();
while(isdigit(ch))x = (x << 1) + (x << 3) + (ch ^ 48), ch = gc();
if(f)return x;
return -x;
}
inline LL Read() {
LL x = 0;
bool f = 1;
char ch = gc();
while(!isdigit(ch))f = ('-' == ch ? 0 : 1), ch = gc();
while(isdigit(ch))x = (x << 1) + (x << 3) + (ch ^ 48), ch = gc();
if(f)return x;
return -x;
}
int gcd(int x,int y) {
return y ? gcd(y, x % y) : x;
}
int lcm(int x,int y) {
return x / gcd(x, y) * y;
}
#define P 1000000007
//#define P 998244353
#define bas 229
inline void ad(int &x, int y) {
x += y;
if(x >= P) x -= P;
}
inline void su(int &x, int y) {
x -= y;
if(x < 0) x += P;
}
inline void cmn(int &x,int y) {
if(y < x) x = y;
}
inline void cmx(int &x,int y) {
if(y > x) x = y;
}
inline void cmn(LL &x, LL y) {
if(y < x) x = y;
}
inline void cmx(LL &x, LL y) {
if(y > x) x = y;
}
int Pow(int x, int y) {
if(y < 0)return Pow(Pow(x, P - 2), -y);
int now = 1 ;
for(; y; y >>= 1, x = 1LL * x * x % P)if(y & 1) now = 1LL * now * x % P;
return now;
}
/*******************************************************************************************************************/
/* */
/*******************************************************************************************************************/
#define N 205
#define K 16
int n, k, a[N], f[N][1 << K], g[N][1 << K], c[1 << K], u[1 << K];
int s(int l,int r){
return (l + r) * (r - l + 1) / 2;
}
int main() {
//int T = read();while(T--)solve();
n = read(), k = read(); int t = (1 << k) - 1;
rp(i, n)a[i] = read() - 1;
rp(i, t)c[i] = c[i >> 1] + (i & 1);
memset(f, 0x3f, sizeof(f));
memset(g, 0x3f, sizeof(g));
f[0][0] = g[n + 1][0] = 0;
rp(i, n){
rep(j, 0, t){
f[i][j] = f[i - 1][j];
if(1 & (j >> a[i])){
int w = j ^ (1 << a[i]), p = (1 << a[i]) - 1;
cmn(f[i][j], f[i - 1][w] - i + c[(w | p) ^ p]);
}
}
}
pr(i, n){
rep(j, 0, t){
g[i][j] = g[i + 1][j];
if(1 & (j >> a[i])){
int w = j ^ (1 << a[i]), p = (1 << a[i]) - 1;
cmn(g[i][j], g[i + 1][w] + i + c[w & p]);
}
}
}
rep(i, 0, t)
rep(j, 0, k - 1)if(1 & (i >> j))
u[i] += c[((1 << j) - 1) & (t ^ i)];
int ans = inf;
rp(i, n - k + 1){
rep(w, 0, t)
cmn(ans, f[i + c[w] - 1][w] + g[i + c[w]][t ^ w] + u[w] + s(i, i + c[w] - 1) - s(i + c[w], i + k - 1));
}
cout << ans << endl;
return 0;
}
Submission Info
| Submission Time |
|
| Task |
D - Pure Straight |
| User |
Inf_Voltage |
| Language |
C++ (GCC 9.2.1) |
| Score |
600 |
| Code Size |
3754 Byte |
| Status |
AC |
| Exec Time |
183 ms |
| Memory |
109076 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
600 / 600 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt |
| All |
01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 02_permutation_01.txt, 02_permutation_02.txt, 02_permutation_03.txt, 02_permutation_04.txt, 02_permutation_05.txt, 02_permutation_06.txt, 02_permutation_07.txt, 02_permutation_08.txt, 02_permutation_09.txt, 02_permutation_10.txt, 02_permutation_11.txt, 02_permutation_12.txt, 02_permutation_13.txt, 02_permutation_14.txt, 02_permutation_15.txt, 03_rand_01.txt, 03_rand_02.txt, 03_rand_03.txt, 03_rand_04.txt, 03_rand_05.txt, 03_rand_06.txt, 03_rand_07.txt, 03_rand_08.txt, 03_rand_09.txt, 03_rand_10.txt, 03_rand_11.txt, 03_rand_12.txt, 03_rand_13.txt, 03_rand_14.txt, 03_rand_15.txt, 03_rand_16.txt, 03_rand_17.txt, 03_rand_18.txt, 03_rand_19.txt, 03_rand_20.txt, 03_rand_21.txt, 03_rand_22.txt, 03_rand_23.txt, 03_rand_24.txt, 03_rand_25.txt, 03_rand_26.txt, 03_rand_27.txt, 03_rand_28.txt, 03_rand_29.txt, 03_rand_30.txt, 03_rand_31.txt, 03_rand_32.txt, 03_rand_33.txt, 04_large_ans_01.txt, 04_large_ans_02.txt, 04_large_ans_03.txt, 04_large_ans_04.txt, 04_large_ans_05.txt, 04_large_ans_06.txt, 04_large_ans_07.txt, 04_large_ans_08.txt, 04_large_ans_09.txt, 04_large_ans_10.txt, 04_large_ans_11.txt, 04_large_ans_12.txt, 05_partition_01.txt, 05_partition_02.txt, 05_partition_03.txt, 05_partition_04.txt, 05_partition_05.txt, 05_partition_06.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 01_sample_01.txt |
AC |
76 ms |
108396 KiB |
| 01_sample_02.txt |
AC |
72 ms |
108572 KiB |
| 01_sample_03.txt |
AC |
70 ms |
108520 KiB |
| 02_permutation_01.txt |
AC |
70 ms |
108524 KiB |
| 02_permutation_02.txt |
AC |
71 ms |
108496 KiB |
| 02_permutation_03.txt |
AC |
68 ms |
108516 KiB |
| 02_permutation_04.txt |
AC |
70 ms |
108520 KiB |
| 02_permutation_05.txt |
AC |
69 ms |
108384 KiB |
| 02_permutation_06.txt |
AC |
67 ms |
108520 KiB |
| 02_permutation_07.txt |
AC |
70 ms |
108468 KiB |
| 02_permutation_08.txt |
AC |
74 ms |
108336 KiB |
| 02_permutation_09.txt |
AC |
73 ms |
108544 KiB |
| 02_permutation_10.txt |
AC |
70 ms |
108592 KiB |
| 02_permutation_11.txt |
AC |
70 ms |
108388 KiB |
| 02_permutation_12.txt |
AC |
73 ms |
108584 KiB |
| 02_permutation_13.txt |
AC |
70 ms |
108596 KiB |
| 02_permutation_14.txt |
AC |
74 ms |
108728 KiB |
| 02_permutation_15.txt |
AC |
75 ms |
109024 KiB |
| 03_rand_01.txt |
AC |
70 ms |
108356 KiB |
| 03_rand_02.txt |
AC |
73 ms |
108468 KiB |
| 03_rand_03.txt |
AC |
72 ms |
108496 KiB |
| 03_rand_04.txt |
AC |
71 ms |
108492 KiB |
| 03_rand_05.txt |
AC |
71 ms |
108412 KiB |
| 03_rand_06.txt |
AC |
69 ms |
108408 KiB |
| 03_rand_07.txt |
AC |
69 ms |
108536 KiB |
| 03_rand_08.txt |
AC |
72 ms |
108388 KiB |
| 03_rand_09.txt |
AC |
73 ms |
108516 KiB |
| 03_rand_10.txt |
AC |
74 ms |
108532 KiB |
| 03_rand_11.txt |
AC |
80 ms |
108420 KiB |
| 03_rand_12.txt |
AC |
85 ms |
108416 KiB |
| 03_rand_13.txt |
AC |
97 ms |
108652 KiB |
| 03_rand_14.txt |
AC |
125 ms |
108788 KiB |
| 03_rand_15.txt |
AC |
128 ms |
108724 KiB |
| 03_rand_16.txt |
AC |
126 ms |
108788 KiB |
| 03_rand_17.txt |
AC |
128 ms |
108748 KiB |
| 03_rand_18.txt |
AC |
127 ms |
108656 KiB |
| 03_rand_19.txt |
AC |
124 ms |
108776 KiB |
| 03_rand_20.txt |
AC |
126 ms |
108652 KiB |
| 03_rand_21.txt |
AC |
124 ms |
108640 KiB |
| 03_rand_22.txt |
AC |
124 ms |
108764 KiB |
| 03_rand_23.txt |
AC |
124 ms |
108768 KiB |
| 03_rand_24.txt |
AC |
178 ms |
108836 KiB |
| 03_rand_25.txt |
AC |
182 ms |
108964 KiB |
| 03_rand_26.txt |
AC |
182 ms |
109000 KiB |
| 03_rand_27.txt |
AC |
179 ms |
108916 KiB |
| 03_rand_28.txt |
AC |
181 ms |
108904 KiB |
| 03_rand_29.txt |
AC |
181 ms |
108836 KiB |
| 03_rand_30.txt |
AC |
179 ms |
108888 KiB |
| 03_rand_31.txt |
AC |
183 ms |
109064 KiB |
| 03_rand_32.txt |
AC |
181 ms |
109004 KiB |
| 03_rand_33.txt |
AC |
179 ms |
108976 KiB |
| 04_large_ans_01.txt |
AC |
182 ms |
108900 KiB |
| 04_large_ans_02.txt |
AC |
124 ms |
108640 KiB |
| 04_large_ans_03.txt |
AC |
179 ms |
109076 KiB |
| 04_large_ans_04.txt |
AC |
129 ms |
108728 KiB |
| 04_large_ans_05.txt |
AC |
181 ms |
108976 KiB |
| 04_large_ans_06.txt |
AC |
128 ms |
108780 KiB |
| 04_large_ans_07.txt |
AC |
180 ms |
108972 KiB |
| 04_large_ans_08.txt |
AC |
124 ms |
108608 KiB |
| 04_large_ans_09.txt |
AC |
178 ms |
108856 KiB |
| 04_large_ans_10.txt |
AC |
125 ms |
108644 KiB |
| 04_large_ans_11.txt |
AC |
181 ms |
109040 KiB |
| 04_large_ans_12.txt |
AC |
125 ms |
108672 KiB |
| 05_partition_01.txt |
AC |
179 ms |
109072 KiB |
| 05_partition_02.txt |
AC |
123 ms |
108660 KiB |
| 05_partition_03.txt |
AC |
182 ms |
109036 KiB |
| 05_partition_04.txt |
AC |
128 ms |
108752 KiB |
| 05_partition_05.txt |
AC |
178 ms |
108960 KiB |
| 05_partition_06.txt |
AC |
124 ms |
108664 KiB |