# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
709446 |
2023-03-13T15:29:19 Z |
myrcella |
Rope (JOI17_rope) |
C++17 |
|
55 ms |
21144 KB |
//by szh
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}
const int maxn = 5010;
int n,m;
int c[maxn*100];
int cntt[maxn][maxn],cnt[maxn];
int ans[maxn];
int tmp[maxn],tmpp[maxn];
void solve(int id) {
rep(i,0,m) {
tmp[i]=tmpp[i]=0;
rep(j,0,m) cntt[i][j]=0;
}
if (id==1) tmpp[c[0]]++;
for (int i=id;i<n;i+=2) {
if (i+1<n) cntt[c[i]][c[i+1]]++,cntt[c[i+1]][c[i]]++,tmpp[c[i]]+=2;
else tmpp[c[i]]++;
if (i+1<n and c[i]!=c[i+1]) {
tmp[c[i]]++;
tmp[c[i+1]]++;
tmpp[c[i+1]]+=2;
}
}
rep(i,0,m) {
ans[i] = min(ans[i],n-cnt[i]);
rep(j,0,m) {
if (i==j) continue;
ans[i] = min(ans[i],(n-tmpp[i])-(cnt[j]-cntt[i][j])+tmp[i]);
// cout<<i<<" "<<j<<" "<<(n-tmpp[i])<<" "<<(cnt[j]-cntt[i][j])<<" "<<tmp[i]<<endl;
}
}
}
int main() {
// freopen("input.txt","r",stdin);
std::ios::sync_with_stdio(false);cin.tie(0);
cin>>n>>m;
rep(i,0,m) ans[i] = n;
rep(i,0,n) {
cin>>c[i];
c[i]--;
cnt[c[i]]++;
}
solve(0);
solve(1);
rep(i,0,m) cout<<ans[i]<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
324 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
256 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
324 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
256 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
6 ms |
980 KB |
Output is correct |
28 |
Correct |
7 ms |
848 KB |
Output is correct |
29 |
Correct |
6 ms |
852 KB |
Output is correct |
30 |
Correct |
5 ms |
832 KB |
Output is correct |
31 |
Correct |
6 ms |
876 KB |
Output is correct |
32 |
Correct |
7 ms |
852 KB |
Output is correct |
33 |
Correct |
8 ms |
856 KB |
Output is correct |
34 |
Correct |
6 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
324 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
256 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
6 ms |
980 KB |
Output is correct |
28 |
Correct |
7 ms |
848 KB |
Output is correct |
29 |
Correct |
6 ms |
852 KB |
Output is correct |
30 |
Correct |
5 ms |
832 KB |
Output is correct |
31 |
Correct |
6 ms |
876 KB |
Output is correct |
32 |
Correct |
7 ms |
852 KB |
Output is correct |
33 |
Correct |
8 ms |
856 KB |
Output is correct |
34 |
Correct |
6 ms |
852 KB |
Output is correct |
35 |
Correct |
10 ms |
4028 KB |
Output is correct |
36 |
Correct |
9 ms |
4044 KB |
Output is correct |
37 |
Correct |
16 ms |
3920 KB |
Output is correct |
38 |
Correct |
11 ms |
3916 KB |
Output is correct |
39 |
Correct |
15 ms |
4052 KB |
Output is correct |
40 |
Correct |
10 ms |
4020 KB |
Output is correct |
41 |
Correct |
10 ms |
4052 KB |
Output is correct |
42 |
Correct |
9 ms |
3284 KB |
Output is correct |
43 |
Correct |
8 ms |
2644 KB |
Output is correct |
44 |
Correct |
11 ms |
4052 KB |
Output is correct |
45 |
Correct |
10 ms |
4052 KB |
Output is correct |
46 |
Correct |
12 ms |
3252 KB |
Output is correct |
47 |
Correct |
15 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
324 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
256 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
6 ms |
980 KB |
Output is correct |
28 |
Correct |
7 ms |
848 KB |
Output is correct |
29 |
Correct |
6 ms |
852 KB |
Output is correct |
30 |
Correct |
5 ms |
832 KB |
Output is correct |
31 |
Correct |
6 ms |
876 KB |
Output is correct |
32 |
Correct |
7 ms |
852 KB |
Output is correct |
33 |
Correct |
8 ms |
856 KB |
Output is correct |
34 |
Correct |
6 ms |
852 KB |
Output is correct |
35 |
Correct |
10 ms |
4028 KB |
Output is correct |
36 |
Correct |
9 ms |
4044 KB |
Output is correct |
37 |
Correct |
16 ms |
3920 KB |
Output is correct |
38 |
Correct |
11 ms |
3916 KB |
Output is correct |
39 |
Correct |
15 ms |
4052 KB |
Output is correct |
40 |
Correct |
10 ms |
4020 KB |
Output is correct |
41 |
Correct |
10 ms |
4052 KB |
Output is correct |
42 |
Correct |
9 ms |
3284 KB |
Output is correct |
43 |
Correct |
8 ms |
2644 KB |
Output is correct |
44 |
Correct |
11 ms |
4052 KB |
Output is correct |
45 |
Correct |
10 ms |
4052 KB |
Output is correct |
46 |
Correct |
12 ms |
3252 KB |
Output is correct |
47 |
Correct |
15 ms |
2644 KB |
Output is correct |
48 |
Incorrect |
55 ms |
21144 KB |
Output isn't correct |
49 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
324 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
256 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
6 ms |
980 KB |
Output is correct |
28 |
Correct |
7 ms |
848 KB |
Output is correct |
29 |
Correct |
6 ms |
852 KB |
Output is correct |
30 |
Correct |
5 ms |
832 KB |
Output is correct |
31 |
Correct |
6 ms |
876 KB |
Output is correct |
32 |
Correct |
7 ms |
852 KB |
Output is correct |
33 |
Correct |
8 ms |
856 KB |
Output is correct |
34 |
Correct |
6 ms |
852 KB |
Output is correct |
35 |
Correct |
10 ms |
4028 KB |
Output is correct |
36 |
Correct |
9 ms |
4044 KB |
Output is correct |
37 |
Correct |
16 ms |
3920 KB |
Output is correct |
38 |
Correct |
11 ms |
3916 KB |
Output is correct |
39 |
Correct |
15 ms |
4052 KB |
Output is correct |
40 |
Correct |
10 ms |
4020 KB |
Output is correct |
41 |
Correct |
10 ms |
4052 KB |
Output is correct |
42 |
Correct |
9 ms |
3284 KB |
Output is correct |
43 |
Correct |
8 ms |
2644 KB |
Output is correct |
44 |
Correct |
11 ms |
4052 KB |
Output is correct |
45 |
Correct |
10 ms |
4052 KB |
Output is correct |
46 |
Correct |
12 ms |
3252 KB |
Output is correct |
47 |
Correct |
15 ms |
2644 KB |
Output is correct |
48 |
Incorrect |
55 ms |
21144 KB |
Output isn't correct |
49 |
Halted |
0 ms |
0 KB |
- |