結果

問題 No.1530 Permutation and Popcount
ユーザー SSRSSSRS
提出日時 2021-06-04 22:01:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,622 bytes
コンパイル時間 1,763 ms
コンパイル使用メモリ 175,116 KB
実行使用メモリ 4,420 KB
最終ジャッジ日時 2023-08-12 12:58:43
合計ジャッジ時間 6,638 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 8 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 8 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 8 ms
4,380 KB
testcase_06 AC 8 ms
4,376 KB
testcase_07 AC 8 ms
4,380 KB
testcase_08 AC 9 ms
4,376 KB
testcase_09 AC 9 ms
4,376 KB
testcase_10 AC 9 ms
4,376 KB
testcase_11 AC 22 ms
4,376 KB
testcase_12 AC 22 ms
4,384 KB
testcase_13 AC 10 ms
4,376 KB
testcase_14 AC 19 ms
4,380 KB
testcase_15 AC 15 ms
4,380 KB
testcase_16 AC 10 ms
4,376 KB
testcase_17 WA -
testcase_18 AC 18 ms
4,380 KB
testcase_19 AC 8 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 20 ms
4,376 KB
testcase_22 AC 20 ms
4,376 KB
testcase_23 AC 19 ms
4,380 KB
testcase_24 AC 10 ms
4,380 KB
testcase_25 AC 19 ms
4,380 KB
testcase_26 AC 12 ms
4,376 KB
testcase_27 AC 22 ms
4,376 KB
testcase_28 AC 21 ms
4,376 KB
testcase_29 AC 14 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 23 ms
4,380 KB
testcase_32 WA -
testcase_33 AC 23 ms
4,376 KB
testcase_34 AC 23 ms
4,376 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 23 ms
4,376 KB
testcase_38 AC 3 ms
4,376 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int INF = 100000000;
int main(){
  random_device rnd;
  mt19937 mt(rnd());
  int N, M;
  cin >> N >> M;
  vector<vector<int>> p(N, vector<int>(N));
  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      p[i][j] = 1 - __builtin_parity((i + 1) * (j + 1));
    }
  }
  vector<bool> X(N, true);
  int D = 0;
  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      D += p[i][j];
    }
  }
  bool ok = false;
  for (int i = 0; i < 100000; i++){
    int x = mt() % N;
    int diff = 0;
    for (int j = 0; j < N; j++){
      diff += p[x][j] * 2;
    }
    if (X[x]){
      diff *= -1;
    }
    if (D + diff == M){
      X[x] = !X[x];
      vector<int> ansx, ansy;
      for (int j = 0; j < N; j++){
        if (X[j]){
          ansx.push_back(j);
        } else {
          ansy.push_back(j);
        }
      }
      int P = ansx.size();
      int Q = ansy.size();
      cout << P << ' ' << Q << endl;
      for (int j = 0; j < P; j++){
        cout << ansx[j] + 1;
        if (j < P - 1){
          cout << ' ';
        }
      }
      cout << endl;
      for (int j = 0; j < Q; j++){
        cout << ansy[j] + 1;
        if (j < Q - 1){
          cout << ' ';
        }
      }
      cout << endl;
      ok = true;
      break;
    }
    int D2 = D + diff;
    int d = abs(D2 - M) - abs(D - M);
    double t = (double) i / 100000;
    double temp = 3.5 - 3.4 * t;
    double p = exp(-d / temp);
    if (!isinf(p)){
      if (mt() % INF < p * INF){
        X[x] = !X[x];
        D = D2;
      }
    }
  }
  if (!ok){
    cout << -1 << endl;
  }
}
0