Submission #282368

# Submission time Handle Problem Language Result Execution time Memory
282368 2020-08-24T11:08:03 Z catalystgma Arranging Shoes (IOI19_shoes) C++14
10 / 100
1 ms 256 KB
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define fi first
#define se second
#define inf (INT_MAX/2-1)
#define infl (1LL<<60)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define sz(a) (int)(a).size()
#define all(a) begin(a),end(a)
#define y0 y5656
#define y1 y7878
#define y2 y9090
#define aaa system("pause");
#define dbg(x) cerr<<(#x)<<": "<<(x)<<'\n',aaa
#define dbga(x,n) cerr<<(#x)<<"[]: ";for(int _=0;_<n;_++)cerr<<x[_]<<' ';cerr<<'\n',aaa
#define dbgs(x) cerr<<(#x)<<"[stl]: ";for(auto _:x)cerr<<_<<' ';cerr<<'\n',aaa
#define dbgp(x) cerr<<(#x)<<": "<<x.fi<<' '<<x.se<<'\n',aaa
#include "shoes.h"

using namespace std;

ll f_la_fel (vi v) {
  int n = sz(v);
  auto to_equal = [&n] (vi v, vi to) {
    vi p1, p2;
    int i, j, z;
    for (i = 0; i < n; i++)
      if (v[i] < 0) p1.pb(i);
    for (i = 0; i < n; i++)
      if (to[i] < 0) p2.pb(i);
    ll ans = 0;
    for (i = 0; i < n/2; i++) ans += abs(p2[i]-p1[i]);
    return ans;
  };
  int x = abs(v[0]);
  vi to1(n, x), to2(n, -x);
  for (int i = 0; i < n; i += 2) {
    to1[i] *= -1;
    to2[i] *= -1;
  }
  return min(to_equal(v, to1), to_equal(v, to2));
}

ll f1000 (vi v) {
  int n = sz(v), i, j, z;
  ll ans = 0;
  for (i = 0; i < n/2; i++) {
    j = 2*i;
    while (j < n && v[j] < 0) j++;
    if (j > 0 && v[j-1] == -v[j]) continue;
    z = j+1;
    while (z < n && v[z] != -v[j]) z++;
    if (j < n && z < n) {
      while (z > j) {
        swap(v[z], v[z-1]);
        ans++;
        z--;
      }
    }
  }
  return ans;
}

ll count_swaps (vi v) {
  int n = sz(v);
  if (n == 2) {
    if (v[0] > v[1]) return 1;
    return 0;
  }
  if (n <= 2000) return f1000(v);
  return f_la_fel(v);
}

//int main () {
//  int n; cin >> n;
//  int i, j, z;
//  vi v(n*2);
//  for (i = 0; i < 2*n; i++) cin >> v[i];
//  cout << count_swaps(v);
//  return 0;
//}

Compilation message

shoes.cpp: In lambda function:
shoes.cpp:32:12: warning: unused variable 'j' [-Wunused-variable]
   32 |     int i, j, z;
      |            ^
shoes.cpp:32:15: warning: unused variable 'z' [-Wunused-variable]
   32 |     int i, j, z;
      |               ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Incorrect 0 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Incorrect 1 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Incorrect 0 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Incorrect 0 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Incorrect 0 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -