結果

問題 No.1687 What the Heck?
ユーザー Iván SotoIván Soto
提出日時 2021-09-24 21:37:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,029 bytes
コンパイル時間 2,197 ms
コンパイル使用メモリ 206,716 KB
実行使用メモリ 14,348 KB
最終ジャッジ日時 2023-09-18 20:53:24
合計ジャッジ時間 4,555 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 179 ms
13,796 KB
testcase_15 AC 175 ms
14,140 KB
testcase_16 AC 170 ms
13,876 KB
testcase_17 AC 8 ms
4,380 KB
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *  author: ivanzuki   
 *  created: Fri Sep 24 2021
**/
#include <bits/stdc++.h>

using namespace std;

string to_string(string s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
template<typename T> void dout(string name, int idx, T arg) {
  cerr << name << " = " << to_string(arg);
}

template<typename T1, typename... T2> void dout(string names, int idx, T1 arg, T2... args) {
  cerr << names.substr(0, names.find(',')) << " = " << to_string(arg) << ", ";
  dout(names.substr(names.find(',') + 2), idx + 1, args...);
}

#ifdef LOCAL
#define debug(...) cerr << "[", dout(#__VA_ARGS__, 0, __VA_ARGS__), cerr << "]" << endl;
#else
#define debug(...) 42
#endif

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> p(n);
  set<int> s;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    --p[i];
    s.insert(i);
  }
  vector<int> ans(n, -1);
  for (int i = n - 1; i >= 0; i--) {
    auto it = s.upper_bound(p[i]);
    if (it != s.end()) {
      ans[i] = *it;
      s.erase(it);
    } else if (it != s.begin()) {
      --it;
      ans[i] = *it;
      s.erase(it);
    } else {
      assert(0);
    }
  }
  debug(ans);
  long long res = 0;
  for (int i = 0; i < n; i++) {
    if (ans[i] > p[i]) {
      res += i + 1;
    } else if (ans[i] < p[i]) {
      res -= i + 1;
    }
  }
  cout << res << '\n';
  return 0;
}
0