結果
問題 |
No.1530 Permutation and Popcount
|
ユーザー |
![]() |
提出日時 | 2021-06-04 22:01:20 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,622 bytes |
コンパイル時間 | 1,986 ms |
コンパイル使用メモリ | 177,952 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-19 14:30:32 |
合計ジャッジ時間 | 5,326 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 WA * 9 |
ソースコード
#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; } }