結果

問題 No.1530 Permutation and Popcount
ユーザー SSRSSSRS
提出日時 2021-06-04 22:05:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,779 bytes
コンパイル時間 2,189 ms
コンパイル使用メモリ 174,448 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-16 08:40:46
合計ジャッジ時間 5,232 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int INF = 100000000;
int f(int x, int l, int r){
  if (l <= x && x <= r){
    return 0;
  } else if (x < l){
    return l - x;
  } else {
    return x - r;
  }
}
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 = f(D2, M - N, M + N) - f(D, M - N, M + N);
    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