Submission #632701

#TimeUsernameProblemLanguageResultExecution timeMemory
632701ghostwriterArranging Shoes (IOI19_shoes)C++14
10 / 100
6 ms9704 KiB
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug.h>
#endif
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define mtp make_tuple
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef long long ll; typedef unsigned long long ull;
typedef double db; typedef long double ldb;
typedef pair<int, int> pi; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll;
typedef string str;
template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
#define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
#define EACH(i, x) for (auto &(i) : (x))
#define WHILE while
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
/*
    Tran The Bao
    CTL - Da Lat
    Practising for VOI23 gold medal
*/
const int N = 2e5 + 1;
int n, c[N];
vi d[N], d1[N];
long long count_swaps(std::vector<int> s) {
	n = sz(s) - 1;
	FOS(i, n, 0)
		if (s[i] < 0) d[-s[i]].pb(i);
		else d1[s[i]].pb(i);
	ll rs = 0;
	FOR(i, 0, n) {
		if (c[i]) continue;
		int ss = abs(s[i]);
		if (s[i] < 0) {
			int pos = d1[ss].back();
			c[pos] = 1;
			d1[ss]._pb();
			rs += pos - i - 1;
			d[ss]._pb();
		}
		else {
			int pos = d[ss].back();
			c[pos] = 1;
			d[ss]._pb();
			rs += pos - i;	
			d1[ss]._pb();
		}
	}
	return rs;
}

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
      |                               ^
shoes.cpp:42:2: note: in expansion of macro 'FOS'
   42 |  FOS(i, n, 0)
      |  ^~~
shoes.cpp:25:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   25 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
shoes.cpp:46:2: note: in expansion of macro 'FOR'
   46 |  FOR(i, 0, n) {
      |  ^~~
#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...