結果

問題 No.1888 Odd Insertion
ユーザー miscalcmiscalc
提出日時 2022-03-06 22:31:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,795 bytes
コンパイル時間 2,195 ms
コンパイル使用メモリ 206,392 KB
実行使用メモリ 36,108 KB
最終ジャッジ日時 2023-09-28 14:11:12
合計ジャッジ時間 49,854 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 65 ms
6,400 KB
testcase_07 AC 64 ms
6,324 KB
testcase_08 AC 544 ms
31,076 KB
testcase_09 AC 540 ms
29,924 KB
testcase_10 AC 562 ms
32,536 KB
testcase_11 AC 534 ms
30,084 KB
testcase_12 AC 559 ms
32,472 KB
testcase_13 AC 543 ms
31,224 KB
testcase_14 AC 529 ms
30,160 KB
testcase_15 AC 558 ms
33,192 KB
testcase_16 AC 1,911 ms
27,864 KB
testcase_17 AC 551 ms
32,400 KB
testcase_18 AC 1,918 ms
28,424 KB
testcase_19 AC 1,911 ms
26,920 KB
testcase_20 AC 1,911 ms
29,920 KB
testcase_21 AC 1,911 ms
27,708 KB
testcase_22 AC 1,911 ms
29,104 KB
testcase_23 AC 1,911 ms
29,440 KB
testcase_24 AC 1,913 ms
29,132 KB
testcase_25 AC 1,912 ms
29,448 KB
testcase_26 AC 555 ms
28,864 KB
testcase_27 AC 511 ms
36,108 KB
testcase_28 AC 609 ms
35,896 KB
testcase_29 AC 277 ms
32,676 KB
testcase_30 AC 1,913 ms
28,964 KB
testcase_31 AC 1,911 ms
34,384 KB
testcase_32 AC 514 ms
35,776 KB
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 N;
vector<int> P, Q, T;
bool isok(int i)
{
  return (Q.at(i) % 2 == T.at(i) % 2);
}

int myrand(double x)
{
  double r = (rand() % 1024) / 1024.0;
  return (r < x ? 0 : 1);
}

clock_t start_time;
int cnt = 0;
void dfs(int i, int last)
{
  if (clock() - start_time >= 1900000)
  {
    cout << "No" << endl;
    exit(0);
  }

  if (i == 0)
  {
    if (isok(i))
    {
      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;
      }
      exit(0);
    }
    return;
  }

  int rnd = myrand(i / (double)N);

  if (rnd == 0)
  {
    if (isok(i))
      dfs(i - 1, rnd);
  }

  swap(Q.at(i - 1), Q.at(i));
  swap(T.at(i - 1), T.at(i));
  if (Q.at(i - 1) < Q.at(i))
    T.at(i)++;
  else
    T.at(i - 1)--;
  if (isok(i))
    dfs(i - 1, rnd);
  swap(Q.at(i - 1), Q.at(i));
  swap(T.at(i - 1), T.at(i));
  if (Q.at(i - 1) < Q.at(i))
    T.at(i)++;
  else
    T.at(i - 1)--;
  
  if (rnd == 1)
  {
    if (isok(i))
      dfs(i - 1, rnd);
  }
}

int main()
{
  srand((unsigned)time(NULL));
  start_time = clock();
  cin >> N;
  P.resize(N);
  for (int i = 0; i < N; i++)
  {
    cin >> P.at(i);
    P.at(i)--;
  }

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

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

  dfs(N - 1, 0);
  cout << "No" << endl;
}
0