# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
51317 | ho94949 | Rope (JOI17_rope) | C++17 | 2552 ms | 13580 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int N, K;
int arr[1010101];
int ans[1010101];
int cnt[1010101];
int evalodd(int c)
{
memset(cnt+1, 0, sizeof(int)*K);
int ans = 0;
if(arr[0] != c) cnt[arr[0]]++;
else ++ans;
for(int i=0; i<(N-1)/2; ++i)
{
int l = arr[2*i+1], r = arr[2*i+2];
if(l == c && r == c)
ans += 2;
else if(l == c || r == c)
ans++;
else
cnt[l]++, cnt[r]++;
}
if(N%2==0)
{
if(arr[N-1] != c)
cnt[arr[N-1]]++;
else
++ans;
}
/*
puts("==O==");
printf("%d\n", c);
for(int i=1; i<=K; ++i)
printf("%d ", cnt[i]);
printf("\n%d\n", ans);
puts("=====");
*/
return ans + *max_element(cnt+1, cnt+K+1);
}
int evaleven(int c)
{
memset(cnt+1, 0, sizeof(int)*K);
int ans = 0;
for(int i=0; i<N/2; ++i)
{
int l = arr[2*i], r = arr[2*i+1];
if(l == c && r == c)
ans += 2;
else if(l == c || r == c)
ans++;
else
cnt[l]++, cnt[r]++;
}
if(N%2==1)
{
if(arr[N-1] != c)
cnt[arr[N-1]]++;
else
++ans;
}
/*
puts("==E==");
printf("%d\n", c);
for(int i=1; i<=K; ++i)
printf("%d ", cnt[i]);
printf("\n%d\n", ans);
puts("=====");
*/
return ans + *max_element(cnt+1, cnt+K+1);
}
int main()
{
scanf("%d%d", &N, &K);
for(int i=0; i<N; ++i) scanf("%d", arr+i);
for(int i=1; i<=K; ++i)
ans[i] = 0x3f3f3f3f;
for(int i=1; i<=K; ++i)
printf("%d\n", N-max(evaleven(i), evalodd(i)));
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |