結果
| 問題 |
No.1530 Permutation and Popcount
|
| コンテスト | |
| ユーザー |
SSRS
|
| 提出日時 | 2021-06-04 22:05:09 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 21 ms / 2,000 ms |
| コード長 | 1,779 bytes |
| コンパイル時間 | 2,027 ms |
| コンパイル使用メモリ | 176,588 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-24 20:37:21 |
| 合計ジャッジ時間 | 3,682 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 41 |
ソースコード
#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;
}
}
SSRS