Submission #20931

# Submission time Handle Problem Language Result Execution time Memory
20931 2017-03-22T00:34:29 Z gs14004 Rope (JOI17_rope) C++14
0 / 100
13 ms 41084 KB
#include <bits/stdc++.h>
typedef long long lint;
typedef long double llf;
using namespace std;
typedef pair<int, int> pi;

int n, m, a[1000005];
int ans[1000005], occ[1000005], chk[1000005];
vector<int> pnt[1000005];

void solve(int s, int e){
	for(int i=1; i<=n; i++) pnt[i].clear();
	if(s > 1) pnt[a[s-1]].push_back(a[s-1]);
	if(e < n) pnt[a[e+1]].push_back(a[e+1]);
	for(int i=s+1; i<=e; i+=2){
		if(a[i-1] == a[i]){
			pnt[a[i]].push_back(a[i]);
			pnt[a[i]].push_back(a[i]);
		}
		else{
			int x = a[i-1], y = a[i];
			pnt[x].push_back(x);
			pnt[x].push_back(y);
			pnt[y].push_back(x);
			pnt[y].push_back(y);
		}
	}
	vector<pi> v;
	for(int i=1; i<=n; i++) v.push_back(pi(occ[i], i));
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	for(int i=1; i<=m; i++){
		int cur = -1e9;
		for(auto &j : pnt[i]) chk[j]++;
		for(auto &j : v){
			cur = max(cur, j.first - chk[j.second]);
			if(!chk[j.second]) break;
		}
		for(auto &j : pnt[i]) chk[j]--;
		ans[i] = min(ans[i], n - occ[i] - cur);
	}
}

int main(){
	scanf("%d %d",&n,&m);
	for(int i=1; i<=n; i++){
		scanf("%d",&a[i]);
	}
	memset(ans, 0x3f, sizeof(ans));
	for(int i=1; i<=n; i++) occ[a[i]]++;
	if(n % 2 == 0) solve(1, n), solve(2, n-1);
	else solve(1, n-1); solve(2, n);
	for(int i=1; i<=m; i++) printf("%d\n", ans[i]);
}

Compilation message

rope.cpp: In function 'int main()':
rope.cpp:45:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&n,&m);
                      ^
rope.cpp:47:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&a[i]);
                    ^

# Verdict Execution time Memory Grader output
1 Correct 6 ms 41084 KB Output is correct
2 Correct 9 ms 41084 KB Output is correct
3 Correct 13 ms 41084 KB Output is correct
4 Correct 13 ms 41084 KB Output is correct
5 Correct 6 ms 41084 KB Output is correct
6 Correct 6 ms 41084 KB Output is correct
7 Correct 3 ms 41084 KB Output is correct
8 Correct 6 ms 41084 KB Output is correct
9 Correct 3 ms 41084 KB Output is correct
10 Correct 9 ms 41084 KB Output is correct
11 Correct 9 ms 41084 KB Output is correct
12 Correct 3 ms 41084 KB Output is correct
13 Correct 9 ms 41084 KB Output is correct
14 Correct 9 ms 41084 KB Output is correct
15 Correct 6 ms 41084 KB Output is correct
16 Correct 9 ms 41084 KB Output is correct
17 Correct 3 ms 41084 KB Output is correct
18 Correct 9 ms 41084 KB Output is correct
19 Correct 9 ms 41084 KB Output is correct
20 Correct 9 ms 41084 KB Output is correct
21 Correct 3 ms 41084 KB Output is correct
22 Incorrect 3 ms 41084 KB Output isn't correct
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 41084 KB Output is correct
2 Correct 9 ms 41084 KB Output is correct
3 Correct 13 ms 41084 KB Output is correct
4 Correct 13 ms 41084 KB Output is correct
5 Correct 6 ms 41084 KB Output is correct
6 Correct 6 ms 41084 KB Output is correct
7 Correct 3 ms 41084 KB Output is correct
8 Correct 6 ms 41084 KB Output is correct
9 Correct 3 ms 41084 KB Output is correct
10 Correct 9 ms 41084 KB Output is correct
11 Correct 9 ms 41084 KB Output is correct
12 Correct 3 ms 41084 KB Output is correct
13 Correct 9 ms 41084 KB Output is correct
14 Correct 9 ms 41084 KB Output is correct
15 Correct 6 ms 41084 KB Output is correct
16 Correct 9 ms 41084 KB Output is correct
17 Correct 3 ms 41084 KB Output is correct
18 Correct 9 ms 41084 KB Output is correct
19 Correct 9 ms 41084 KB Output is correct
20 Correct 9 ms 41084 KB Output is correct
21 Correct 3 ms 41084 KB Output is correct
22 Incorrect 3 ms 41084 KB Output isn't correct
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 41084 KB Output is correct
2 Correct 9 ms 41084 KB Output is correct
3 Correct 13 ms 41084 KB Output is correct
4 Correct 13 ms 41084 KB Output is correct
5 Correct 6 ms 41084 KB Output is correct
6 Correct 6 ms 41084 KB Output is correct
7 Correct 3 ms 41084 KB Output is correct
8 Correct 6 ms 41084 KB Output is correct
9 Correct 3 ms 41084 KB Output is correct
10 Correct 9 ms 41084 KB Output is correct
11 Correct 9 ms 41084 KB Output is correct
12 Correct 3 ms 41084 KB Output is correct
13 Correct 9 ms 41084 KB Output is correct
14 Correct 9 ms 41084 KB Output is correct
15 Correct 6 ms 41084 KB Output is correct
16 Correct 9 ms 41084 KB Output is correct
17 Correct 3 ms 41084 KB Output is correct
18 Correct 9 ms 41084 KB Output is correct
19 Correct 9 ms 41084 KB Output is correct
20 Correct 9 ms 41084 KB Output is correct
21 Correct 3 ms 41084 KB Output is correct
22 Incorrect 3 ms 41084 KB Output isn't correct
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 41084 KB Output is correct
2 Correct 9 ms 41084 KB Output is correct
3 Correct 13 ms 41084 KB Output is correct
4 Correct 13 ms 41084 KB Output is correct
5 Correct 6 ms 41084 KB Output is correct
6 Correct 6 ms 41084 KB Output is correct
7 Correct 3 ms 41084 KB Output is correct
8 Correct 6 ms 41084 KB Output is correct
9 Correct 3 ms 41084 KB Output is correct
10 Correct 9 ms 41084 KB Output is correct
11 Correct 9 ms 41084 KB Output is correct
12 Correct 3 ms 41084 KB Output is correct
13 Correct 9 ms 41084 KB Output is correct
14 Correct 9 ms 41084 KB Output is correct
15 Correct 6 ms 41084 KB Output is correct
16 Correct 9 ms 41084 KB Output is correct
17 Correct 3 ms 41084 KB Output is correct
18 Correct 9 ms 41084 KB Output is correct
19 Correct 9 ms 41084 KB Output is correct
20 Correct 9 ms 41084 KB Output is correct
21 Correct 3 ms 41084 KB Output is correct
22 Incorrect 3 ms 41084 KB Output isn't correct
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 41084 KB Output is correct
2 Correct 9 ms 41084 KB Output is correct
3 Correct 13 ms 41084 KB Output is correct
4 Correct 13 ms 41084 KB Output is correct
5 Correct 6 ms 41084 KB Output is correct
6 Correct 6 ms 41084 KB Output is correct
7 Correct 3 ms 41084 KB Output is correct
8 Correct 6 ms 41084 KB Output is correct
9 Correct 3 ms 41084 KB Output is correct
10 Correct 9 ms 41084 KB Output is correct
11 Correct 9 ms 41084 KB Output is correct
12 Correct 3 ms 41084 KB Output is correct
13 Correct 9 ms 41084 KB Output is correct
14 Correct 9 ms 41084 KB Output is correct
15 Correct 6 ms 41084 KB Output is correct
16 Correct 9 ms 41084 KB Output is correct
17 Correct 3 ms 41084 KB Output is correct
18 Correct 9 ms 41084 KB Output is correct
19 Correct 9 ms 41084 KB Output is correct
20 Correct 9 ms 41084 KB Output is correct
21 Correct 3 ms 41084 KB Output is correct
22 Incorrect 3 ms 41084 KB Output isn't correct
23 Halted 0 ms 0 KB -