Submission #758875

#TimeUsernameProblemLanguageResultExecution timeMemory
758875TrumlingArranging Shoes (IOI19_shoes)C++14
10 / 100
1 ms212 KiB
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std; 
 
typedef long long ll;
#define pb push_back
#define F first
#define S second
#define enter cout<<'\n';
#define INF 99999999999999999
#define MOD 1000000007
#define all(x) x.begin(),x.end()
 
long long count_swaps(std::vector<int> s) 
{
	ll nn=s.size();

	ll answ=0;
for(int r=0;r<nn;r+=2)
{
	ll found[nn+1]={ };
	for(int i=r;i<nn;i++)
		if(s[i]>0 && !found[s[i]])
			found[s[i]]=i;
	pair<int,int>ans;
	ans={INF,0};

	for(int i=r;i<nn;i++)
		if(s[i]<0)
		{
			if(found[-s[i]]<i && ans.F>abs(r-i)+abs(found[s[i]]-r))
			ans={abs(r-i)+abs(r+1-found[s[i]])+1,i};

			if(found[-s[i]]>i && ans.F>abs(r-i)+abs(r+1-found[s[i]]))
			ans={abs(r-i)+abs(r+1-found[s[i]]),i};
		}

		for(int j=ans.S-1;j>=r;j--)
		{
			swap(s[j],s[j+1]);
			answ++;
		}

		for(int j=r+1;j<nn;j++)
		if(s[j]+s[r]==0)
		{
			for(int c=j-1;c>=r+1;c--)
			{
			swap(s[c],s[c+1]);
			answ++;
			}
			break;
		}
}
	
	return answ;
}

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:28:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   28 |  for(int i=r;i<nn;i++)
      |  ^~~
shoes.cpp:38:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   38 |   for(int j=ans.S-1;j>=r;j--)
      |   ^~~
shoes.cpp:31:54: warning: array subscript -1 is below array bounds of 'll [(<anonymous> + 1)]' {aka 'long long int [(<anonymous> + 1)]'} [-Warray-bounds]
   31 |    if(found[-s[i]]<i && ans.F>abs(r-i)+abs(found[s[i]]-r))
      |                                            ~~~~~~~~~~^
shoes.cpp:34:58: warning: array subscript -1 is below array bounds of 'll [(<anonymous> + 1)]' {aka 'long long int [(<anonymous> + 1)]'} [-Warray-bounds]
   34 |    if(found[-s[i]]>i && ans.F>abs(r-i)+abs(r+1-found[s[i]]))
      |                                                ~~~~~~~~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...