Submission #1305823

#TimeUsernameProblemLanguageResultExecution timeMemory
1305823ayazArranging Shoes (IOI19_shoes)C++20
85 / 100
1093 ms12156 KiB
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#include "shoes.h"

#include <bits/stdc++.h>
using namespace std;
#define isz(x) (int)x.size()
long long count_swaps(std::vector<int> s) {
  vector<int> a = s;
  #define int long long
  int n = isz(a);
  bool ok = true;
  for (int i = 0; i < n / 2; i++) {
    ok &= (a[i] + a[i + n / 2] == 0);
    ok &= (a[i] < 0);
  }
  if (ok) {
    return (n / 2) * (n / 2 - 1) / 2;
  }
  set<int> st;
  for (int i = 0; i < n; i++) st.insert(a[i]);
  if (isz(st) == 2) {
    int ans = 0;
    set<int> pos[2];
    for (int i = 0; i < n; i++) {
      pos[a[i] < 0 ? 0 : 1].insert(i);
    }
    for (int i = 0; i < n; i++) {
      if (i % 2 == 0 && a[i] > 0) {
        auto it = pos[0].upper_bound(i);
        ans += *it - i;
        swap(a[i], a[*it]);
        pos[0].erase(it);
        pos[1].erase(pos[1].find(i));
        pos[0].insert(i);
        pos[1].insert(*it);
        continue;
      }
      if (i % 2 == 1 && a[i] < 0) {
        auto it = pos[1].upper_bound(i);
        ans += *it - i;
        swap(a[i], a[*it]);
        pos[1].erase(it);
        pos[0].erase(pos[0].find(i));
        pos[1].insert(i);
        pos[0].insert(*it);
      }
    }
    return ans;
  }
  if (n == 2) {
    return (a[0] > 0);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0 && a[i] > 0) {
      int d = 1e9;
      for (int j = i + 1; j < n; j++) {
        if (a[j] + a[i] == 0) {
          d = j;
          break;
        }
      }
      ans += (d - i);
      for (int j = d; j > i; j--) swap(a[j], a[j - 1]);
      continue;
    }
    if (i % 2 == 1 && (a[i] < 0 || (a[i - 1] + a[i]) != 0)) {
      int d = 1e9;
      for (int j = i + 1; j < n; j++) {
        if (a[j] + a[i - 1] == 0) {
          d = j;
          break;
        }
      }
      ans += (d - i);
      for (int j = d; j > i; j--) swap(a[j], a[j - 1]);
    }
  }
  for (int i = 0; i < n; i += 2) {
    ans += (a[i] > 0);
  }
  return ans;
}

Compilation message (stderr)

shoes.cpp:20:39: warning: bad option '-fwhole-program' to pragma 'optimize' [-Wpragmas]
   20 | #pragma GCC optimize("-fwhole-program")
      |                                       ^
shoes.cpp:27:41: warning: bad option '-fstrict-overflow' to pragma 'optimize' [-Wpragmas]
   27 | #pragma GCC optimize("-fstrict-overflow")
      |                                         ^
shoes.cpp:29:41: warning: bad option '-fcse-skip-blocks' to pragma 'optimize' [-Wpragmas]
   29 | #pragma GCC optimize("-fcse-skip-blocks")
      |                                         ^
shoes.cpp:43:51: warning: bad option '-funsafe-loop-optimizations' to pragma 'optimize' [-Wpragmas]
   43 | #pragma GCC optimize("-funsafe-loop-optimizations")
      |                                                   ^
In file included from shoes.cpp:46:
shoes.h:7:41: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
    7 | long long count_swaps(std::vector<int> S);
      |                                         ^
shoes.h:7:41: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
shoes.h:7:41: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
shoes.h:7:41: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
shoes.h:7:41: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
shoes.h:7:41: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
shoes.h:7:41: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
shoes.h:7:41: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
shoes.cpp:51:41: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   51 | long long count_swaps(std::vector<int> s) {
      |                                         ^
shoes.cpp:51:41: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
shoes.cpp:51:41: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
shoes.cpp:51:41: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
#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...