이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <assert.h>
using namespace std;
int S1[2005];
int S2[2005];
int all[2005];
int a[2005]={0};
int b[2005]={0};
bool F(int a,int b)
{
return a<b;
}
long long count_swaps(std::vector<int> S)
{
long long ans1=0,small,what,t;
int i,j,k,N=S.size();
for(i=0;i<N/2;i++)
{
for(j=1;j<=N/2;j++)
{
a[j]=100000000;
b[j]=100000000;
}
for(j=2*i;j<N;j++)
{
if(S[j]<0) b[0-S[j]]=min(b[0-S[j]],j);
else a[S[j]]=min(a[S[j]],j);
}
small=1000000000;
for(j=1;j<=N/2;j++)
{
t=a[j]+b[j];
if(a[j]>b[j]) t++;
if(t<=small)
{
small=t;
what=j;
}
}
for(j=2*i;j<N;j++)
{
if(S[j]==0-what)
{
for(k=j;k>2*i;k--)
{
swap(S[k],S[k-1]);
ans1++;
}
break;
}
}
for(j=2*i+1;j<N;j++)
{
if(S[j]==what)
{
for(k=j;k>2*i+1;k--)
{
swap(S[k],S[k-1]);
ans1++;
}
break;
}
}
}
return ans1;
}
컴파일 시 표준 에러 (stderr) 메시지
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:46:23: warning: 'what' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(S[j]==0-what)
~^~~~~| # | 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... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |