Submission #298246

#TimeUsernameProblemLanguageResultExecution timeMemory
298246RayaabualjamalArranging Shoes (IOI19_shoes)C++14
Compilation error
0 ms0 KiB
#include "shoes.h"
#include <iostream> 
#include <vector> 
#include <cstdio>
#define rep(i,a,b) for(int i = a; i<b; i++)
#define rep(i,a,b) for(int i = a; i>b; i--)
#define pb push_back
using namespace std;
long long count_swaps(vector<int> s) {
	int n = s.size();
	long long ans = 0; 
	rep(i,0,n){
		if(s[i]<0){
			int pos;
			rep(j,i+1,n){
				if((-s[i]) == s[j]){
					pos = j;
					break;
				}
			}
			per(j,pos, i+1){
				swap(s[j], s[j-1]);
				ans++;
			}
		}else{
			int pos;
			rep(j,i+1,n){
				if((-s[i]) == s[j]){
					pos = j;
					break;
				}
			}
			per(j,pos, i){
				swap(s[j], s[j-1]);
				ans++;
			}
		}
		//cout << s[i] << endl;
		i++;
	}
	//cout << "ans: " << ans << endl;
	return ans;
}

Compilation message (stderr)

shoes.cpp:6: warning: "rep" redefined
    6 | #define rep(i,a,b) for(int i = a; i>b; i--)
      | 
shoes.cpp:5: note: this is the location of the previous definition
    5 | #define rep(i,a,b) for(int i = a; i<b; i++)
      | 
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:21:8: error: 'j' was not declared in this scope
   21 |    per(j,pos, i+1){
      |        ^
shoes.cpp:21:4: error: 'per' was not declared in this scope
   21 |    per(j,pos, i+1){
      |    ^~~
shoes.cpp:33:8: error: 'j' was not declared in this scope
   33 |    per(j,pos, i){
      |        ^
shoes.cpp:33:4: error: 'per' was not declared in this scope
   33 |    per(j,pos, i){
      |    ^~~