結果

問題 No.1888 Odd Insertion
ユーザー miscalcmiscalc
提出日時 2021-09-17 20:55:31
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 352 ms / 2,000 ms
コード長 1,385 bytes
コンパイル時間 2,452 ms
コンパイル使用メモリ 203,788 KB
実行使用メモリ 8,084 KB
最終ジャッジ日時 2023-09-11 15:50:58
合計ジャッジ時間 17,160 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 62 ms
6,156 KB
testcase_07 AC 64 ms
6,156 KB
testcase_08 AC 342 ms
7,804 KB
testcase_09 AC 352 ms
7,924 KB
testcase_10 AC 343 ms
7,728 KB
testcase_11 AC 334 ms
7,784 KB
testcase_12 AC 337 ms
7,788 KB
testcase_13 AC 335 ms
7,724 KB
testcase_14 AC 346 ms
8,084 KB
testcase_15 AC 337 ms
7,776 KB
testcase_16 AC 68 ms
6,320 KB
testcase_17 AC 331 ms
7,796 KB
testcase_18 AC 68 ms
6,240 KB
testcase_19 AC 68 ms
6,324 KB
testcase_20 AC 67 ms
6,340 KB
testcase_21 AC 66 ms
6,304 KB
testcase_22 AC 66 ms
6,148 KB
testcase_23 AC 67 ms
6,252 KB
testcase_24 AC 65 ms
6,244 KB
testcase_25 AC 68 ms
6,228 KB
testcase_26 AC 331 ms
7,740 KB
testcase_27 AC 332 ms
7,912 KB
testcase_28 AC 337 ms
7,804 KB
testcase_29 AC 65 ms
6,168 KB
testcase_30 AC 62 ms
6,172 KB
testcase_31 AC 62 ms
6,320 KB
testcase_32 AC 344 ms
7,840 KB
testcase_33 AC 336 ms
7,828 KB
testcase_34 AC 338 ms
7,784 KB
testcase_35 AC 326 ms
7,728 KB
testcase_36 AC 337 ms
7,752 KB
testcase_37 AC 333 ms
7,904 KB
testcase_38 AC 339 ms
7,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#include <atcoder/fenwicktree>
using namespace atcoder;

bool isok(vector<int> &Q, vector<int> &T, int i)
{
  return (Q.at(i) % 2 == T.at(i) % 2);
}

int main()
{
  int N;
  cin >> N;
  vector<int> P(N);
  for (int i = 0; i < N; i++)
  {
    cin >> P.at(i);
    P.at(i)--;
  }

  vector<int> Q(N);
  for (int i = 0; i < N; i++)
  {
    Q.at(P.at(i)) = i;
  }
  reverse(Q.begin(), Q.end());

  fenwick_tree<int> fw(N);
  vector<int> T(N);
  for (int i = 0; i < N; i++)
  {
    T.at(i) = fw.sum(0, Q.at(i));
    fw.add(Q.at(i), 1);
  }

  for (int i = N - 1; i >= 1; i--)
  {
    if (Q.at(i - 1) > Q.at(i) && !isok(Q, T, i - 1))
    {
      swap(Q.at(i - 1), Q.at(i));
      swap(T.at(i - 1), T.at(i));
      T.at(i)++;
    }
    if (Q.at(i - 1) < Q.at(i) && !isok(Q, T, i))
    {
      swap(Q.at(i - 1), Q.at(i));
      swap(T.at(i - 1), T.at(i));
      T.at(i - 1)--;
    }

    if (!isok(Q, T, i))
    {
      cout << "No" << endl;
      return 0;
    }
  }
  if (!isok(Q, T, 0))
  {
    cout << "No" << endl;
    return 0;
  }

  vector<int> X(N), Y(N);
  for (int i = 0; i < N; i++)
  {
    X.at(i) = P.at(Q.at(i));
    Y.at(i) = Q.at(i) - T.at(i);
  }
  reverse(X.begin(), X.end());
  reverse(Y.begin(), Y.end());

  cout << "Yes" << endl;
  for (int i = 0; i < N; i++)
  {
    cout << X.at(i) + 1 << " " << Y.at(i) + 1 << endl;
  }
}
0