Submission #530849

# Submission time Handle Problem Language Result Execution time Memory
530849 2022-02-27T01:39:02 Z M1v1savva Arranging Shoes (IOI19_shoes) C++17
10 / 100
1 ms 292 KB
#include "shoes.h"
#include <bits/stdc++.h>

#define sz(x) (int)(x).size()
#define forn(i, x) for (int i = 0; i < (int)x; i++)
#define pb push_back
#define rforn(i, x) for (int i = (int)x - 1; i >= 0; i--)
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ff first
#define ss second

using namespace std;

template<class T>
void print(T a) {
    for (auto x : a)
        cout << x << ' ';
    cout << endl;
}

long long count_swaps(vector<int> S) {
	vector<int> a = S;
	int n = sz(a);

    map<int, int> scores;
    map<int, int> prev;

    long long ans = 0;
    forn (i, 2 * n) {
    	int val = a[i];
    	scores[abs(val)]++;

		if (scores[abs(val)] % 2 == 0) {
			ans += i - prev[abs(val)];
			if (val > 0)
				ans--;
		} else {
			prev[abs(val)] = i;
		}
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 0 ms 288 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 0 ms 292 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 292 KB Output is correct
2 Incorrect 0 ms 292 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 0 ms 288 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 0 ms 288 KB Output isn't correct
4 Halted 0 ms 0 KB -