Submission #909601

# Submission time Handle Problem Language Result Execution time Memory
909601 2024-01-17T09:41:24 Z MilosMilutinovic Rope (JOI17_rope) C++14
80 / 100
2500 ms 127548 KB
#include<bits/stdc++.h>
 
#define pb push_back
#define fi first
#define se second
#define mp make_pair
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
 
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
 
ll readint(){
	ll x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n,m,c[1000005],cnt[1000005],res[1000005];
vector<int> g[1000005];

void solve(int x){
	for(int i=1;i<=m;i++){
		cnt[i]=0;
		g[i].clear();
	}
	for(int i=1;i<=n;i++) cnt[c[i]]++;
	for(int i=1+x;i+1<=n;i+=2){
		if(c[i]==c[i+1]) continue;
		g[c[i]].push_back(c[i+1]);
		g[c[i+1]].push_back(c[i]);
	}
	multiset<int> st;
	for(int i=1;i<=m;i++) st.insert(cnt[i]);
	for(int i=1;i<=m;i++){
		vector<int> xs;
		for(int j:g[i]) xs.pb(j);
		sort(xs.begin(),xs.end());
		xs.erase(unique(xs.begin(),xs.end()),xs.end());
		for(int j:xs) st.erase(st.find(cnt[j]));
		for(int j:g[i]) cnt[j]--;
		for(int j:xs) st.insert(cnt[j]);
		st.erase(st.find(cnt[i]));
		int mx=0;
		if(!st.empty()) mx=*prev(st.end());
		res[i]=min(res[i],n-(cnt[i]+mx));
		st.insert(cnt[i]);
		for(int j:xs) st.erase(st.find(cnt[j]));
		for(int j:g[i]) cnt[j]++;
		for(int j:xs) st.insert(cnt[j]);
	}
}

int main() {
	n=readint(); m=readint();
	for(int i=1;i<=n;i++) c[i]=readint();
	for(int i=1;i<=m;i++) res[i]=n;
	solve(0);
	solve(1);
	for(int i=1;i<=m;i++) printf("%d\n",res[i]);
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 29272 KB Output is correct
2 Correct 8 ms 29276 KB Output is correct
3 Correct 9 ms 29276 KB Output is correct
4 Correct 9 ms 29276 KB Output is correct
5 Correct 9 ms 29276 KB Output is correct
6 Correct 10 ms 29276 KB Output is correct
7 Correct 9 ms 29276 KB Output is correct
8 Correct 8 ms 29276 KB Output is correct
9 Correct 9 ms 29308 KB Output is correct
10 Correct 9 ms 29276 KB Output is correct
11 Correct 9 ms 29276 KB Output is correct
12 Correct 9 ms 29276 KB Output is correct
13 Correct 9 ms 29276 KB Output is correct
14 Correct 9 ms 29276 KB Output is correct
15 Correct 9 ms 29276 KB Output is correct
16 Correct 9 ms 29276 KB Output is correct
17 Correct 9 ms 29276 KB Output is correct
18 Correct 10 ms 29272 KB Output is correct
19 Correct 10 ms 29276 KB Output is correct
20 Correct 10 ms 29276 KB Output is correct
21 Correct 8 ms 29332 KB Output is correct
22 Correct 11 ms 29276 KB Output is correct
23 Correct 9 ms 29276 KB Output is correct
24 Correct 9 ms 29272 KB Output is correct
25 Correct 12 ms 29276 KB Output is correct
26 Correct 9 ms 29348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 29272 KB Output is correct
2 Correct 8 ms 29276 KB Output is correct
3 Correct 9 ms 29276 KB Output is correct
4 Correct 9 ms 29276 KB Output is correct
5 Correct 9 ms 29276 KB Output is correct
6 Correct 10 ms 29276 KB Output is correct
7 Correct 9 ms 29276 KB Output is correct
8 Correct 8 ms 29276 KB Output is correct
9 Correct 9 ms 29308 KB Output is correct
10 Correct 9 ms 29276 KB Output is correct
11 Correct 9 ms 29276 KB Output is correct
12 Correct 9 ms 29276 KB Output is correct
13 Correct 9 ms 29276 KB Output is correct
14 Correct 9 ms 29276 KB Output is correct
15 Correct 9 ms 29276 KB Output is correct
16 Correct 9 ms 29276 KB Output is correct
17 Correct 9 ms 29276 KB Output is correct
18 Correct 10 ms 29272 KB Output is correct
19 Correct 10 ms 29276 KB Output is correct
20 Correct 10 ms 29276 KB Output is correct
21 Correct 8 ms 29332 KB Output is correct
22 Correct 11 ms 29276 KB Output is correct
23 Correct 9 ms 29276 KB Output is correct
24 Correct 9 ms 29272 KB Output is correct
25 Correct 12 ms 29276 KB Output is correct
26 Correct 9 ms 29348 KB Output is correct
27 Correct 15 ms 30040 KB Output is correct
28 Correct 13 ms 30068 KB Output is correct
29 Correct 15 ms 30044 KB Output is correct
30 Correct 16 ms 29788 KB Output is correct
31 Correct 17 ms 30044 KB Output is correct
32 Correct 16 ms 30040 KB Output is correct
33 Correct 15 ms 30044 KB Output is correct
34 Correct 13 ms 29788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 29272 KB Output is correct
2 Correct 8 ms 29276 KB Output is correct
3 Correct 9 ms 29276 KB Output is correct
4 Correct 9 ms 29276 KB Output is correct
5 Correct 9 ms 29276 KB Output is correct
6 Correct 10 ms 29276 KB Output is correct
7 Correct 9 ms 29276 KB Output is correct
8 Correct 8 ms 29276 KB Output is correct
9 Correct 9 ms 29308 KB Output is correct
10 Correct 9 ms 29276 KB Output is correct
11 Correct 9 ms 29276 KB Output is correct
12 Correct 9 ms 29276 KB Output is correct
13 Correct 9 ms 29276 KB Output is correct
14 Correct 9 ms 29276 KB Output is correct
15 Correct 9 ms 29276 KB Output is correct
16 Correct 9 ms 29276 KB Output is correct
17 Correct 9 ms 29276 KB Output is correct
18 Correct 10 ms 29272 KB Output is correct
19 Correct 10 ms 29276 KB Output is correct
20 Correct 10 ms 29276 KB Output is correct
21 Correct 8 ms 29332 KB Output is correct
22 Correct 11 ms 29276 KB Output is correct
23 Correct 9 ms 29276 KB Output is correct
24 Correct 9 ms 29272 KB Output is correct
25 Correct 12 ms 29276 KB Output is correct
26 Correct 9 ms 29348 KB Output is correct
27 Correct 15 ms 30040 KB Output is correct
28 Correct 13 ms 30068 KB Output is correct
29 Correct 15 ms 30044 KB Output is correct
30 Correct 16 ms 29788 KB Output is correct
31 Correct 17 ms 30044 KB Output is correct
32 Correct 16 ms 30040 KB Output is correct
33 Correct 15 ms 30044 KB Output is correct
34 Correct 13 ms 29788 KB Output is correct
35 Correct 62 ms 30212 KB Output is correct
36 Correct 69 ms 30040 KB Output is correct
37 Correct 72 ms 30044 KB Output is correct
38 Correct 58 ms 30044 KB Output is correct
39 Correct 58 ms 30044 KB Output is correct
40 Correct 39 ms 30300 KB Output is correct
41 Correct 38 ms 30296 KB Output is correct
42 Correct 32 ms 30300 KB Output is correct
43 Correct 33 ms 30300 KB Output is correct
44 Correct 39 ms 30296 KB Output is correct
45 Correct 38 ms 30300 KB Output is correct
46 Correct 33 ms 30300 KB Output is correct
47 Correct 33 ms 30300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 29272 KB Output is correct
2 Correct 8 ms 29276 KB Output is correct
3 Correct 9 ms 29276 KB Output is correct
4 Correct 9 ms 29276 KB Output is correct
5 Correct 9 ms 29276 KB Output is correct
6 Correct 10 ms 29276 KB Output is correct
7 Correct 9 ms 29276 KB Output is correct
8 Correct 8 ms 29276 KB Output is correct
9 Correct 9 ms 29308 KB Output is correct
10 Correct 9 ms 29276 KB Output is correct
11 Correct 9 ms 29276 KB Output is correct
12 Correct 9 ms 29276 KB Output is correct
13 Correct 9 ms 29276 KB Output is correct
14 Correct 9 ms 29276 KB Output is correct
15 Correct 9 ms 29276 KB Output is correct
16 Correct 9 ms 29276 KB Output is correct
17 Correct 9 ms 29276 KB Output is correct
18 Correct 10 ms 29272 KB Output is correct
19 Correct 10 ms 29276 KB Output is correct
20 Correct 10 ms 29276 KB Output is correct
21 Correct 8 ms 29332 KB Output is correct
22 Correct 11 ms 29276 KB Output is correct
23 Correct 9 ms 29276 KB Output is correct
24 Correct 9 ms 29272 KB Output is correct
25 Correct 12 ms 29276 KB Output is correct
26 Correct 9 ms 29348 KB Output is correct
27 Correct 15 ms 30040 KB Output is correct
28 Correct 13 ms 30068 KB Output is correct
29 Correct 15 ms 30044 KB Output is correct
30 Correct 16 ms 29788 KB Output is correct
31 Correct 17 ms 30044 KB Output is correct
32 Correct 16 ms 30040 KB Output is correct
33 Correct 15 ms 30044 KB Output is correct
34 Correct 13 ms 29788 KB Output is correct
35 Correct 62 ms 30212 KB Output is correct
36 Correct 69 ms 30040 KB Output is correct
37 Correct 72 ms 30044 KB Output is correct
38 Correct 58 ms 30044 KB Output is correct
39 Correct 58 ms 30044 KB Output is correct
40 Correct 39 ms 30300 KB Output is correct
41 Correct 38 ms 30296 KB Output is correct
42 Correct 32 ms 30300 KB Output is correct
43 Correct 33 ms 30300 KB Output is correct
44 Correct 39 ms 30296 KB Output is correct
45 Correct 38 ms 30300 KB Output is correct
46 Correct 33 ms 30300 KB Output is correct
47 Correct 33 ms 30300 KB Output is correct
48 Correct 878 ms 42748 KB Output is correct
49 Correct 865 ms 42488 KB Output is correct
50 Correct 888 ms 42836 KB Output is correct
51 Correct 637 ms 42416 KB Output is correct
52 Correct 501 ms 41072 KB Output is correct
53 Correct 453 ms 41808 KB Output is correct
54 Correct 334 ms 40908 KB Output is correct
55 Correct 338 ms 41044 KB Output is correct
56 Correct 262 ms 40508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 29272 KB Output is correct
2 Correct 8 ms 29276 KB Output is correct
3 Correct 9 ms 29276 KB Output is correct
4 Correct 9 ms 29276 KB Output is correct
5 Correct 9 ms 29276 KB Output is correct
6 Correct 10 ms 29276 KB Output is correct
7 Correct 9 ms 29276 KB Output is correct
8 Correct 8 ms 29276 KB Output is correct
9 Correct 9 ms 29308 KB Output is correct
10 Correct 9 ms 29276 KB Output is correct
11 Correct 9 ms 29276 KB Output is correct
12 Correct 9 ms 29276 KB Output is correct
13 Correct 9 ms 29276 KB Output is correct
14 Correct 9 ms 29276 KB Output is correct
15 Correct 9 ms 29276 KB Output is correct
16 Correct 9 ms 29276 KB Output is correct
17 Correct 9 ms 29276 KB Output is correct
18 Correct 10 ms 29272 KB Output is correct
19 Correct 10 ms 29276 KB Output is correct
20 Correct 10 ms 29276 KB Output is correct
21 Correct 8 ms 29332 KB Output is correct
22 Correct 11 ms 29276 KB Output is correct
23 Correct 9 ms 29276 KB Output is correct
24 Correct 9 ms 29272 KB Output is correct
25 Correct 12 ms 29276 KB Output is correct
26 Correct 9 ms 29348 KB Output is correct
27 Correct 15 ms 30040 KB Output is correct
28 Correct 13 ms 30068 KB Output is correct
29 Correct 15 ms 30044 KB Output is correct
30 Correct 16 ms 29788 KB Output is correct
31 Correct 17 ms 30044 KB Output is correct
32 Correct 16 ms 30040 KB Output is correct
33 Correct 15 ms 30044 KB Output is correct
34 Correct 13 ms 29788 KB Output is correct
35 Correct 62 ms 30212 KB Output is correct
36 Correct 69 ms 30040 KB Output is correct
37 Correct 72 ms 30044 KB Output is correct
38 Correct 58 ms 30044 KB Output is correct
39 Correct 58 ms 30044 KB Output is correct
40 Correct 39 ms 30300 KB Output is correct
41 Correct 38 ms 30296 KB Output is correct
42 Correct 32 ms 30300 KB Output is correct
43 Correct 33 ms 30300 KB Output is correct
44 Correct 39 ms 30296 KB Output is correct
45 Correct 38 ms 30300 KB Output is correct
46 Correct 33 ms 30300 KB Output is correct
47 Correct 33 ms 30300 KB Output is correct
48 Correct 878 ms 42748 KB Output is correct
49 Correct 865 ms 42488 KB Output is correct
50 Correct 888 ms 42836 KB Output is correct
51 Correct 637 ms 42416 KB Output is correct
52 Correct 501 ms 41072 KB Output is correct
53 Correct 453 ms 41808 KB Output is correct
54 Correct 334 ms 40908 KB Output is correct
55 Correct 338 ms 41044 KB Output is correct
56 Correct 262 ms 40508 KB Output is correct
57 Execution timed out 2582 ms 127548 KB Time limit exceeded
58 Halted 0 ms 0 KB -