#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <assert.h>
using namespace std;
int all[15];
int Find[15];
int S1[1005];
bool F(int a,int b)
{
return a<b;
}
long long count_swaps(std::vector<int> S)
{
long long ans1=0,ans2=1e18,N=S.size(),i,j,k,now=0;
long long t;
for(i=0;i<N;i++) if(S[i]>0) all[now++]=S[i];
sort(all,all+N/2,F);
/*do
{
now=0;
for(i=0;i<N;i++) S1[i]=S[i];
for(i=0;i<N/2;i++)
{
for(j=2*i;j<N;j++)
{
if(S1[j]==0-all[i])
{
for(k=j;k>2*i;k--)
{
now++;
swap(S1[k],S1[k-1]);
}
break;
}
}
for(j=2*i+1;j<N;j++)
{
if(S1[j]==all[i])
{
for(k=j;k>2*i+1;k--)
{
now++;
swap(S1[k],S1[k-1]);
}
break;
}
}
}
ans2=min(ans2,now);
if(now==ans2) for(i=0;i<N/2;i++) Find[i]=all[i];
}while(next_permutation(all,all+N/2));*/
for(i=0;i<N;i++) S1[i]=S[i];
for(i=0;i<N/2;i++)
{
for(j=2*i;j<N;j++)
{
if(S[j]<0)
{
t=0-S1[j];
for(k=j;k>2*i;k--)
{
ans1++;
swap(S1[k],S1[k-1]);
}
break;
}
}
for(j=2*i+1;j<N;j++)
{
if(S1[j]==t)
{
for(k=j;k>2*i+1;k--)
{
ans1++;
swap(S1[k],S1[k-1]);
}
break;
}
}
}
ans2=0;
for(i=0;i<N;i++) S1[i]=S[i];
for(i=0;i<N/2;i++)
{
for(j=2*i;j<N;j++)
{
if(S[j]>=0)
{
t=0-S1[j];
break;
}
}
for(j=2*i;j<N;j++)
{
if(S1[j]==t)
{
for(k=j;k>2*i;k--)
{
ans2++;
swap(S1[k],S1[k-1]);
}
break;
}
}
for(j=2*i+1;j<N;j++)
{
if(S1[j]==0-t)
{
for(k=j;k>2*i+1;k--)
{
ans2++;
swap(S1[k],S1[k-1]);
}
break;
}
}
}
return min(ans1,ans2);
}
Compilation message
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:77:13: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(S1[j]==t)
^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
380 KB |
Output is correct |
4 |
Incorrect |
2 ms |
252 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Runtime error |
33 ms |
3832 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
380 KB |
Output is correct |
4 |
Incorrect |
2 ms |
252 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
380 KB |
Output is correct |
4 |
Incorrect |
2 ms |
252 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |