結果

問題 No.1888 Odd Insertion
ユーザー miscalcmiscalc
提出日時 2021-11-12 20:45:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,665 bytes
コンパイル時間 2,840 ms
コンパイル使用メモリ 205,428 KB
実行使用メモリ 36,116 KB
最終ジャッジ日時 2023-09-11 15:58:23
合計ジャッジ時間 30,973 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,504 KB
testcase_06 AC 64 ms
6,232 KB
testcase_07 AC 64 ms
6,248 KB
testcase_08 AC 541 ms
30,860 KB
testcase_09 AC 536 ms
30,004 KB
testcase_10 AC 544 ms
32,324 KB
testcase_11 AC 531 ms
29,640 KB
testcase_12 AC 546 ms
32,076 KB
testcase_13 AC 538 ms
31,076 KB
testcase_14 AC 533 ms
29,748 KB
testcase_15 AC 557 ms
32,912 KB
testcase_16 AC 1,909 ms
27,508 KB
testcase_17 AC 550 ms
32,484 KB
testcase_18 AC 1,914 ms
28,156 KB
testcase_19 AC 1,911 ms
26,064 KB
testcase_20 AC 1,911 ms
29,784 KB
testcase_21 AC 1,911 ms
27,064 KB
testcase_22 AC 1,911 ms
28,440 KB
testcase_23 AC 1,910 ms
29,420 KB
testcase_24 AC 1,911 ms
29,436 KB
testcase_25 AC 1,911 ms
29,176 KB
testcase_26 AC 556 ms
28,864 KB
testcase_27 AC 520 ms
36,116 KB
testcase_28 AC 610 ms
35,876 KB
testcase_29 AC 282 ms
30,864 KB
testcase_30 AC 1,913 ms
30,764 KB
testcase_31 AC 1,911 ms
34,508 KB
testcase_32 AC 528 ms
35,780 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);
}

clock_t start_time;
int cnt = 0;
void dfs(int i)
{
  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 = rand() % 2;

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

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

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);
  cout << "No" << endl;
}
0