Submission #286234

# Submission time Handle Problem Language Result Execution time Memory
286234 2020-08-30T08:39:05 Z BeanZ Arranging Shoes (IOI19_shoes) C++14
0 / 100
6 ms 5120 KB
#include <bits/stdc++.h>
#include "shoes.h"

using namespace std;

#define ll long long
#define endl '\n'

const int N = 2e5 + 5;
vector<ll> node[100005];
ll a[200005];
ll count_swaps(vector<int> s){
        ll ans = 0;
        int n = s.size() / 2;
        ll cnt = 1;
        for (int i = 0; i < (2 * n); i++){
                if (s[i] > 0){
                        node[s[i]].push_back(cnt - 1);
                        cnt += 2;
                }
        }
        for (int i = 1; i <= n; i++){
                if (node[i].size() == 0) continue;
                reverse(node[i].begin(), node[i].end());
        }
        for (int i = 0; i < (2 * n); i++){
                if (s[i] < 0){
                        ans = ans + abs(i - node[s[i]].back());
                        node[s[i]].pop_back();
                }
        }
        return ans;
}
/*
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        if (fopen("VietCT.INP", "r")){
                freopen("VietCT.INP", "r", stdin);
                freopen("VietCT.OUT", "w", stdout);
        }
        ll n;
        cin >> n;
        for (int i = 1; i <= 2 * n; i++) cin >> a[i];
        ll now = 1, ans = 0;
        for (int i = 1; i <= (2 * n); i++){
                if (a[i] < 0){
                        ans = ans + abs(i - now);
                        now += 2;
                }
        }
        cout << ans;
}
*/
/*
*/

Compilation message

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:28:61: warning: array subscript -1 is below array bounds of 'std::vector<long long int> [100005]' [-Warray-bounds]
   28 |                         ans = ans + abs(i - node[s[i]].back());
      |                                                             ^
shoes.cpp:10:12: note: while referencing 'node'
   10 | vector<ll> node[100005];
      |            ^~~~
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 5120 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 5120 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 5120 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 5120 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 5120 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 5120 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -