# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
173124 |
2020-01-03T12:03:07 Z |
songc |
Rope (JOI17_rope) |
C++14 |
|
45 ms |
47880 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
int N, M;
int A[1010101];
int Ecnt[1010101], E[1010101], EM, ES;
int Ocnt[1010101], O[1010101], OM, OS;
vector<int> Ec[1010101], Oc[1010101];
int Eup(int k, int v){
Ecnt[E[k]]--;
if (!Ecnt[EM]) EM--;
else if (EM == ES && Ecnt[EM]<=1) ES--;
else if (!Ecnt[ES]) ES--;
E[k] += v;
if (EM < E[k]) EM = E[k];
else if (ES < E[k]) ES = E[k];
Ecnt[E[k]]++;
}
int Oup(int k, int v){
Ocnt[O[k]]--;
if (!Ocnt[OM]) OM--;
else if (OM == OS && Ocnt[OM]<=1) OS--;
else if (!Ocnt[OS]) OS--;
O[k] += v;
if (OM < O[k]) OM = O[k];
else if (OS < O[k]) OS = O[k];
Ocnt[O[k]]++;
}
int main(){
//freopen("in.txt", "r", stdin);
scanf("%d %d", &N, &M);
if (M == 1){
puts("0");
return 0;
}
Ecnt[0]=Ocnt[0]=M;
for (int i=1; i<=N; i++) scanf("%d", &A[i]);
for (int i=1; i+1<=N; i+=2){
Eup(A[i], 1);
Eup(A[i+1], 1);
if (A[i] != A[i+1]){
Ec[A[i]].push_back(A[i+1]);
Ec[A[i+1]].push_back(A[i]);
}
}
for (int i=2; i+1<=N; i+=2){
Oup(A[i], 1);
Oup(A[i+1], 1);
if (A[i] != A[i+1]){
Oc[A[i]].push_back(A[i+1]);
Oc[A[i+1]].push_back(A[i]);
}
}
if (N & 1){
Eup(A[N], 1);
Oup(A[1], 1);
}
else{
Oup(A[1], 1);
Oup(A[N], 1);
}
for (int i=1; i<=M; i++){
int ans=0;
for (int x : Ec[i]) Eup(x, -1);
for (int x : Oc[i]) Oup(x, -1);
if (E[i] == EM) ans = max(ans, E[i]+ES);
else ans = max(ans, E[i]+EM);
if (O[i] == OM) ans = max(ans, O[i]+OS);
else ans = max(ans, O[i]+OM);
printf("%d\n", N-ans);
for (int x : Ec[i]) Eup(x, 1);
for (int x : Oc[i]) Oup(x, 1);
}
return 0;
}
Compilation message
rope.cpp: In function 'int Eup(int, int)':
rope.cpp:21:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
rope.cpp: In function 'int Oup(int, int)':
rope.cpp:32:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
rope.cpp: In function 'int main()':
rope.cpp:36:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &N, &M);
~~~~~^~~~~~~~~~~~~~~~~
rope.cpp:42:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (int i=1; i<=N; i++) scanf("%d", &A[i]);
~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
47880 KB |
Output is correct |
2 |
Correct |
45 ms |
47864 KB |
Output is correct |
3 |
Correct |
45 ms |
47864 KB |
Output is correct |
4 |
Incorrect |
45 ms |
47836 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
47880 KB |
Output is correct |
2 |
Correct |
45 ms |
47864 KB |
Output is correct |
3 |
Correct |
45 ms |
47864 KB |
Output is correct |
4 |
Incorrect |
45 ms |
47836 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
47880 KB |
Output is correct |
2 |
Correct |
45 ms |
47864 KB |
Output is correct |
3 |
Correct |
45 ms |
47864 KB |
Output is correct |
4 |
Incorrect |
45 ms |
47836 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
47880 KB |
Output is correct |
2 |
Correct |
45 ms |
47864 KB |
Output is correct |
3 |
Correct |
45 ms |
47864 KB |
Output is correct |
4 |
Incorrect |
45 ms |
47836 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
47880 KB |
Output is correct |
2 |
Correct |
45 ms |
47864 KB |
Output is correct |
3 |
Correct |
45 ms |
47864 KB |
Output is correct |
4 |
Incorrect |
45 ms |
47836 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |