답안 #709449

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
709449 2023-03-13T15:30:10 Z myrcella Rope (JOI17_rope) C++17
80 / 100
2500 ms 246196 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*1000];
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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 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 328 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 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 340 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 324 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 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 328 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 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 328 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 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 340 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 324 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 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 328 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
27 Correct 7 ms 980 KB Output is correct
28 Correct 7 ms 852 KB Output is correct
29 Correct 7 ms 912 KB Output is correct
30 Correct 6 ms 852 KB Output is correct
31 Correct 7 ms 980 KB Output is correct
32 Correct 7 ms 844 KB Output is correct
33 Correct 6 ms 852 KB Output is correct
34 Correct 7 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 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 328 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 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 340 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 324 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 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 328 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
27 Correct 7 ms 980 KB Output is correct
28 Correct 7 ms 852 KB Output is correct
29 Correct 7 ms 912 KB Output is correct
30 Correct 6 ms 852 KB Output is correct
31 Correct 7 ms 980 KB Output is correct
32 Correct 7 ms 844 KB Output is correct
33 Correct 6 ms 852 KB Output is correct
34 Correct 7 ms 852 KB Output is correct
35 Correct 10 ms 4116 KB Output is correct
36 Correct 10 ms 4052 KB Output is correct
37 Correct 10 ms 3880 KB Output is correct
38 Correct 10 ms 3920 KB Output is correct
39 Correct 11 ms 4052 KB Output is correct
40 Correct 13 ms 4008 KB Output is correct
41 Correct 10 ms 4052 KB Output is correct
42 Correct 8 ms 3252 KB Output is correct
43 Correct 9 ms 2644 KB Output is correct
44 Correct 11 ms 4116 KB Output is correct
45 Correct 11 ms 4052 KB Output is correct
46 Correct 9 ms 3284 KB Output is correct
47 Correct 10 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 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 328 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 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 340 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 324 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 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 328 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
27 Correct 7 ms 980 KB Output is correct
28 Correct 7 ms 852 KB Output is correct
29 Correct 7 ms 912 KB Output is correct
30 Correct 6 ms 852 KB Output is correct
31 Correct 7 ms 980 KB Output is correct
32 Correct 7 ms 844 KB Output is correct
33 Correct 6 ms 852 KB Output is correct
34 Correct 7 ms 852 KB Output is correct
35 Correct 10 ms 4116 KB Output is correct
36 Correct 10 ms 4052 KB Output is correct
37 Correct 10 ms 3880 KB Output is correct
38 Correct 10 ms 3920 KB Output is correct
39 Correct 11 ms 4052 KB Output is correct
40 Correct 13 ms 4008 KB Output is correct
41 Correct 10 ms 4052 KB Output is correct
42 Correct 8 ms 3252 KB Output is correct
43 Correct 9 ms 2644 KB Output is correct
44 Correct 11 ms 4116 KB Output is correct
45 Correct 11 ms 4052 KB Output is correct
46 Correct 9 ms 3284 KB Output is correct
47 Correct 10 ms 2644 KB Output is correct
48 Correct 150 ms 54780 KB Output is correct
49 Correct 149 ms 56056 KB Output is correct
50 Correct 155 ms 56024 KB Output is correct
51 Correct 105 ms 23268 KB Output is correct
52 Correct 115 ms 15892 KB Output is correct
53 Correct 145 ms 55980 KB Output is correct
54 Correct 142 ms 56052 KB Output is correct
55 Correct 151 ms 56012 KB Output is correct
56 Correct 141 ms 56040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 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 328 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 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 340 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 324 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 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 328 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
27 Correct 7 ms 980 KB Output is correct
28 Correct 7 ms 852 KB Output is correct
29 Correct 7 ms 912 KB Output is correct
30 Correct 6 ms 852 KB Output is correct
31 Correct 7 ms 980 KB Output is correct
32 Correct 7 ms 844 KB Output is correct
33 Correct 6 ms 852 KB Output is correct
34 Correct 7 ms 852 KB Output is correct
35 Correct 10 ms 4116 KB Output is correct
36 Correct 10 ms 4052 KB Output is correct
37 Correct 10 ms 3880 KB Output is correct
38 Correct 10 ms 3920 KB Output is correct
39 Correct 11 ms 4052 KB Output is correct
40 Correct 13 ms 4008 KB Output is correct
41 Correct 10 ms 4052 KB Output is correct
42 Correct 8 ms 3252 KB Output is correct
43 Correct 9 ms 2644 KB Output is correct
44 Correct 11 ms 4116 KB Output is correct
45 Correct 11 ms 4052 KB Output is correct
46 Correct 9 ms 3284 KB Output is correct
47 Correct 10 ms 2644 KB Output is correct
48 Correct 150 ms 54780 KB Output is correct
49 Correct 149 ms 56056 KB Output is correct
50 Correct 155 ms 56024 KB Output is correct
51 Correct 105 ms 23268 KB Output is correct
52 Correct 115 ms 15892 KB Output is correct
53 Correct 145 ms 55980 KB Output is correct
54 Correct 142 ms 56052 KB Output is correct
55 Correct 151 ms 56012 KB Output is correct
56 Correct 141 ms 56040 KB Output is correct
57 Execution timed out 2529 ms 246196 KB Time limit exceeded
58 Halted 0 ms 0 KB -