結果

問題 No.1888 Odd Insertion
ユーザー miscalcmiscalc
提出日時 2022-02-14 09:41:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,156 bytes
コンパイル時間 2,030 ms
コンパイル使用メモリ 203,052 KB
実行使用メモリ 7,336 KB
最終ジャッジ日時 2023-09-11 16:00:37
合計ジャッジ時間 61,520 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 57 ms
7,092 KB
testcase_07 AC 59 ms
7,016 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 69 ms
6,992 KB
testcase_17 WA -
testcase_18 AC 69 ms
6,988 KB
testcase_19 AC 70 ms
6,992 KB
testcase_20 AC 70 ms
6,944 KB
testcase_21 AC 68 ms
7,152 KB
testcase_22 AC 66 ms
7,000 KB
testcase_23 AC 69 ms
7,020 KB
testcase_24 AC 69 ms
7,148 KB
testcase_25 AC 72 ms
7,012 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 62 ms
7,036 KB
testcase_30 AC 61 ms
7,148 KB
testcase_31 AC 64 ms
6,992 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#include <atcoder/fenwicktree>
using namespace atcoder;

int main()
{
  clock_t start_time = clock();

  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;
  }

  fenwick_tree<int> fw(N);

  vector<int> X(N), Y(N);
  for (int i = 0; i < N - 1; i++)
  {
    int y1 = fw.sum(0, Q.at(i));
    int y2 = fw.sum(0, Q.at(i + 1));

    if (y1 % 2 != 0 && y2 % 2 != 0)
    {
      cout << "No" << endl;
      return 0;
    }

    if (y2 % 2 == 0)
    {
      if (y1 % 2 != 0 || Q.at(i) < Q.at(i + 1))
      {
        swap(Q.at(i), Q.at(i + 1));
        swap(y1, y2);
      }
    }

    X.at(i) = P.at(Q.at(i));
    Y.at(i) = y1;

    fw.add(Q.at(i), 1);
  }
  X.back() = P.at(Q.back());
  Y.back() = fw.sum(0, Q.back());
  if (Y.back() % 2 != 0)
  {
    cout << "No" << endl;
    return 0;
  }

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

  while (clock() - start_time < 1900000)
  {
    cout << 1;
  }
}
0