이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 (v < 0 ){
if (!Ecnt[EM]) EM--;
else if (EM == ES && Ecnt[EM]<=1) ES--;
else if (!Ecnt[ES]) ES--;
}
E[k] += v;
if (v > 0){
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 (v < 0){
if (!Ocnt[OM]) OM--;
else if (OM == OS && Ocnt[OM]<=1) OS--;
else if (!Ocnt[OS]) OS--;
}
O[k] += v;
if (v > 0){
if (OM < O[k]) OM = O[k];
else if (OS < O[k]) OS = O[k];
}
Ocnt[O[k]]++;
}
int main(){
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;
}
컴파일 시 표준 에러 (stderr) 메시지
rope.cpp: In function 'int Eup(int, int)':
rope.cpp:25:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
rope.cpp: In function 'int Oup(int, int)':
rope.cpp:40:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
rope.cpp: In function 'int main()':
rope.cpp:43: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:49: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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |