답안 #336187

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
336187 2020-12-15T01:23:59 Z YJU Rope (JOI17_rope) C++14
45 / 100
2500 ms 2028 KB
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=1e6+5;
const ll K=350;
const ld pi=acos(-1);
const ll INF=(1LL<<60);
#define SQ(i) ((i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()

ll u[N],n,m,cnt[N],ans[N],dp[N];

ll ct(ll id,ll c){
	ll ti=0;
	if(u[id]!=c)++ti;
	if(u[id-1]!=c)++ti;
	return ti;
}

ll ck(ll a,ll b){
	ll ta=0,tb=0,tmp=INF;
	if(a==b)return n-cnt[a];
	REP1(i,n){
		if(u[i]==a)++ta;
		if(u[i]==b)++tb;
		dp[i]=INF;
		if(i>=2){
			dp[i]=min(dp[i],dp[i-2]+min(ct(i,a),ct(i,b)));
		}else{
			dp[i]=1-(u[i]==a||u[i]==b?1:0);
		}
		tmp=min(tmp,dp[i]+(n-i)-max(cnt[a]-ta,cnt[b]-tb));
	}
	return tmp;
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n>>m;
	REP1(i,n)cin>>u[i],++cnt[u[i]];
	REP1(i,m)ans[i]=INF;
	REP1(i,m)REP1(j,i){
		ll tmp=ck(i,j);
		ans[i]=min(ans[i],tmp);
		ans[j]=min(ans[j],tmp);
	}
	REP1(i,m)cout<<ans[i]<<"\n";
	return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 37 ms 2028 KB Output is correct
28 Correct 13 ms 1900 KB Output is correct
29 Correct 32 ms 1900 KB Output is correct
30 Correct 16 ms 1900 KB Output is correct
31 Correct 39 ms 1900 KB Output is correct
32 Correct 13 ms 1920 KB Output is correct
33 Correct 32 ms 1900 KB Output is correct
34 Correct 16 ms 1900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 37 ms 2028 KB Output is correct
28 Correct 13 ms 1900 KB Output is correct
29 Correct 32 ms 1900 KB Output is correct
30 Correct 16 ms 1900 KB Output is correct
31 Correct 39 ms 1900 KB Output is correct
32 Correct 13 ms 1920 KB Output is correct
33 Correct 32 ms 1900 KB Output is correct
34 Correct 16 ms 1900 KB Output is correct
35 Execution timed out 2586 ms 1900 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 37 ms 2028 KB Output is correct
28 Correct 13 ms 1900 KB Output is correct
29 Correct 32 ms 1900 KB Output is correct
30 Correct 16 ms 1900 KB Output is correct
31 Correct 39 ms 1900 KB Output is correct
32 Correct 13 ms 1920 KB Output is correct
33 Correct 32 ms 1900 KB Output is correct
34 Correct 16 ms 1900 KB Output is correct
35 Execution timed out 2586 ms 1900 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 37 ms 2028 KB Output is correct
28 Correct 13 ms 1900 KB Output is correct
29 Correct 32 ms 1900 KB Output is correct
30 Correct 16 ms 1900 KB Output is correct
31 Correct 39 ms 1900 KB Output is correct
32 Correct 13 ms 1920 KB Output is correct
33 Correct 32 ms 1900 KB Output is correct
34 Correct 16 ms 1900 KB Output is correct
35 Execution timed out 2586 ms 1900 KB Time limit exceeded
36 Halted 0 ms 0 KB -