Submission #758386

#TimeUsernameProblemLanguageResultExecution timeMemory
758386TrumlingArranging 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();

	vector<int>v(nn);
	for(int i=0;i<nn;i+=2)
	v[i/2]=i;

	ll ans=INF;
	do
	{
	bool tf=1;
	ll idx=0;
	vector<int>g(nn,-1);

	for(int i=0;i<nn;i++)
			if(s[i]<0)
				g[i]=v[idx++];


	if(!tf)
	continue;

	ll curr=0;

	vector<int>now(nn);
	
	for(int i=0;i<nn;i++)
		now[i]=i;
	
	bool taken[nn]={ };
	idx=0;

for(int r=0;r<nn;r++)
	for(int i=0;i<nn;i++)
	{
		if(g[i]==idx)
		{
		for(int j=i-1;j>=idx;j--)
		{
			swap(now[j],now[j+1]);
			swap(g[j],g[j+1]);
			curr++;
		}

		for(int j=idx+1;j<nn;j++)
		if(!taken[j] && s[now[j]]+s[now[idx]]==0)
		{
			taken[j]=1;
			for(int c=j-1;c>=idx+1;c--)
			{
			swap(now[c],now[c+1]);
			swap(g[c],g[c+1]);
			curr++;
			}
		}
		idx+=2;
		break;
		}
	}	
		
	ans=min(ans,curr);
	}while(next_permutation(all(v)));	
	

	return ans;
}

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:47:1: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   47 | for(int r=0;r<nn;r++)
      | ^~~
shoes.cpp:75:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   75 |  ans=min(ans,curr);
      |  ^~~
#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...