// #pragma GCC optimize("O3,Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define MP make_pair
#define pb push_back
#define REP(i,n) for(int i = 0; (i) < (n); (i)++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
const double EPS = 0.00001;
const int INF = 1e7;
const int N = 3e5+5;
const int ALPH = 26;
const int LGN = 25;
constexpr int MOD = 1e9+7;
int n = 5,m,q;
vector<vector<int> > valid;
bool shorten(vector<int> &x) {
for(int i = 1; i < x.size(); i++) {
int j1 = i, j2 = i - 1;
bool f1 = 1;
while(j1 < x.size() && j2 >= 0) {
if(x[j1] != x[j2]) {
f1 = 0;
break;
}
j1++; j2--;
}
if(f1) {
// cout << "wtf:" << i << " " << j1 << " " << j2 << "\n";
if(j1 == x.size()) {
while((int)x.size() > i) {
x.pop_back();
}
return 1;
}
else {
vector<int> tmp;
for(int j = i; j < x.size(); j++) {
tmp.pb(x[j]);
}
swap(tmp, x);
return 1;
}
}
}
return 0;
}
void answer(vector<int> ar) {
vector<int> tmp = ar;
while(shorten(ar)) {}
if(ar.size() <= 2) {
valid.pb(tmp);
}
}
void gen_arr(int ind, vector<int> &ar) {
if(ind == n) {
answer(ar);
return;
}
REP(i, 2) {
ar[ind] = i;
gen_arr(ind + 1, ar);
}
}
vector<int> a;
int get_cost(array<int,2> x) {
int cost = INF;
for(auto &arr : valid) {
int ret = 0;
for(int i = 0; i < n; i++) {
if(a[i] != x[arr[i]]) ret++;
}
cost = min(cost, ret);
ret = 0;
for(int i = 0; i < n; i++) {
if(a[i] != x[!arr[i]]) ret++;
}
cost = min(cost, ret);
}
return cost;
}
inline void solve() {
cin >> n >> m;
vector<int> ar;
ar.resize(n);
a.resize(n);
gen_arr(0, ar);
REP(i, n) cin >> a[i];
vector<int> res(m + 1, INF);
for(int i = 1; i <= m; i++) {
for(int j = i; j <= m; j++) {
int cur = get_cost({i, j});
res[i] = min(res[i], cur);
res[j] = min(res[j], cur);
}
}
for(int i = 1; i<=m; i++) {
cout << res[i] << "\n";
}
}
signed main() {
fastio();
int test = 1;
//cin>>test;
while(test--) {
solve();
}
}
Compilation message
rope.cpp: In function 'bool shorten(std::vector<int>&)':
rope.cpp:31:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for(int i = 1; i < x.size(); i++) {
| ~~^~~~~~~~~~
rope.cpp:34:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | while(j1 < x.size() && j2 >= 0) {
| ~~~^~~~~~~~~~
rope.cpp:43:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | if(j1 == x.size()) {
| ~~~^~~~~~~~~~~
rope.cpp:51:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for(int j = i; j < x.size(); j++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
4 ms |
348 KB |
Output is correct |
4 |
Correct |
16 ms |
484 KB |
Output is correct |
5 |
Correct |
10 ms |
348 KB |
Output is correct |
6 |
Correct |
4 ms |
344 KB |
Output is correct |
7 |
Correct |
7 ms |
344 KB |
Output is correct |
8 |
Correct |
13 ms |
460 KB |
Output is correct |
9 |
Correct |
13 ms |
500 KB |
Output is correct |
10 |
Correct |
14 ms |
496 KB |
Output is correct |
11 |
Correct |
1 ms |
352 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
504 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
460 KB |
Output is correct |
23 |
Correct |
0 ms |
452 KB |
Output is correct |
24 |
Correct |
0 ms |
452 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
4 ms |
348 KB |
Output is correct |
4 |
Correct |
16 ms |
484 KB |
Output is correct |
5 |
Correct |
10 ms |
348 KB |
Output is correct |
6 |
Correct |
4 ms |
344 KB |
Output is correct |
7 |
Correct |
7 ms |
344 KB |
Output is correct |
8 |
Correct |
13 ms |
460 KB |
Output is correct |
9 |
Correct |
13 ms |
500 KB |
Output is correct |
10 |
Correct |
14 ms |
496 KB |
Output is correct |
11 |
Correct |
1 ms |
352 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
504 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
460 KB |
Output is correct |
23 |
Correct |
0 ms |
452 KB |
Output is correct |
24 |
Correct |
0 ms |
452 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Execution timed out |
2554 ms |
9164 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
4 ms |
348 KB |
Output is correct |
4 |
Correct |
16 ms |
484 KB |
Output is correct |
5 |
Correct |
10 ms |
348 KB |
Output is correct |
6 |
Correct |
4 ms |
344 KB |
Output is correct |
7 |
Correct |
7 ms |
344 KB |
Output is correct |
8 |
Correct |
13 ms |
460 KB |
Output is correct |
9 |
Correct |
13 ms |
500 KB |
Output is correct |
10 |
Correct |
14 ms |
496 KB |
Output is correct |
11 |
Correct |
1 ms |
352 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
504 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
460 KB |
Output is correct |
23 |
Correct |
0 ms |
452 KB |
Output is correct |
24 |
Correct |
0 ms |
452 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Execution timed out |
2554 ms |
9164 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
4 ms |
348 KB |
Output is correct |
4 |
Correct |
16 ms |
484 KB |
Output is correct |
5 |
Correct |
10 ms |
348 KB |
Output is correct |
6 |
Correct |
4 ms |
344 KB |
Output is correct |
7 |
Correct |
7 ms |
344 KB |
Output is correct |
8 |
Correct |
13 ms |
460 KB |
Output is correct |
9 |
Correct |
13 ms |
500 KB |
Output is correct |
10 |
Correct |
14 ms |
496 KB |
Output is correct |
11 |
Correct |
1 ms |
352 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
504 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
460 KB |
Output is correct |
23 |
Correct |
0 ms |
452 KB |
Output is correct |
24 |
Correct |
0 ms |
452 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Execution timed out |
2554 ms |
9164 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
4 ms |
348 KB |
Output is correct |
4 |
Correct |
16 ms |
484 KB |
Output is correct |
5 |
Correct |
10 ms |
348 KB |
Output is correct |
6 |
Correct |
4 ms |
344 KB |
Output is correct |
7 |
Correct |
7 ms |
344 KB |
Output is correct |
8 |
Correct |
13 ms |
460 KB |
Output is correct |
9 |
Correct |
13 ms |
500 KB |
Output is correct |
10 |
Correct |
14 ms |
496 KB |
Output is correct |
11 |
Correct |
1 ms |
352 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
504 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
460 KB |
Output is correct |
23 |
Correct |
0 ms |
452 KB |
Output is correct |
24 |
Correct |
0 ms |
452 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Execution timed out |
2554 ms |
9164 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |