QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#294307 | #5529. Most Annoying Constructive Problem | zhoukangyang# | WA | 142ms | 4132kb | C++14 | 5.8kb | 2023-12-30 11:44:56 | 2023-12-30 11:44:56 |
Judging History
answer
#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define vi vector <int>
#define sz(a) ((int) (a).size())
#define me(f, x) memset(f, x, sizeof(f))
#define uint unsigned int
#define ull unsigned long long
#define i128 __int128
#define pb emplace_back
using namespace std;
const int N = 1007;
int n, k;
int p[N];
bool h[N][N];
int vis[N];
vi V[N];
int cnt;
void Gen() {
cnt = 0;
L(i, 1, n) {
L(j, i + 1, n) {
h[i][j] = p[i] > p[j];
}
}
L(i, 1, n) {
L(j, i + 1, n) {
h[i][j] ^= h[i][j - 1];
}
}
R(i, n, 1) {
L(j, i + 1, n) {
h[i][j] ^= h[i + 1][j];
}
}
L(i, 1, n) {
L(j, i + 1, n) {
cnt += h[i][j];
}
}
}
void upm(int l, int r) {
L(j, l, r)
R(i, j - 1, 1)
cnt -= h[i][j],
h[i][j] = h[i + 1][j] ^ h[i][j - 1] ^ h[i + 1][j - 1] ^ (p[i] > p[j]),
cnt += h[i][j];
R(i, r, l)
L(j, i + 1, n)
cnt -= h[i][j],
h[i][j] = h[i + 1][j] ^ h[i][j - 1] ^ h[i + 1][j - 1] ^ (p[i] > p[j]),
cnt += h[i][j];
}
mt19937_64 orz;
const int mx = 1e9;
inline int rad(int l, int r) {
return orz() % (r - l + 1) + l;
}
inline bool update(int x, int nw) {
if(x < k && nw >= x) {
return 1;
}
if(x > k && nw <= x) {
return 1;
}
return orz() % mx < exp(-(double) abs(nw - k) / n * 10) * mx;
}
void prt() {
cout << "YES\n";
L(i, 1, n) cout << p[i] << ' ';
cout << '\n';
}
void solve(int tn, int tm) {
n = tn, k = tm;
if(k < n * (n - 1) / 4) {
L(i, 1, n) {
p[i] = i;
}
} else {
L(d, 1, n / 2) {
p[d * 2 - 1] = d * 2 + 1;
p[d * 2] = d * 2 - 1;
if(1 < d && d < n / 2) {
--p[d * 2];
}
if(d == n / 2)
--p[d * 2], --p[d * 2 - 1];
}
if(n % 2)p[n] = n;
}
Gen();
if(cnt == k)return prt();
while(true){
int lst = cnt;
if(orz() % 2 == 0) {
int d = rad(1, n - 2);
swap(p[d], p[d + 1]), swap(p[d + 1], p[d + 2]);
upm(d, d + 2);
if(!update(lst, cnt)) {
swap(p[d + 1], p[d + 2]), swap(p[d], p[d + 1]);
upm(d, d + 2);
// Gen();
}
}else {
int d = rad(1, n - 2);
swap(p[d + 1], p[d + 2]), swap(p[d], p[d + 1]);
upm(d, d + 2);
if(!update(lst, cnt)) {
swap(p[d], p[d + 1]), swap(p[d + 1], p[d + 2]);
upm(d, d + 2);
}
}
if(cnt == k) {
Gen();
prt();
break;
}
if(orz()%(n*20)==0){
solve(tn,tm);
return;
}
}
}
void mini_solve(int tn, int tm) {
n = tn, k = tm;
if(k < n * (n - 1) / 4) {
L(i, 1, n) {
p[i] = i;
}
} else {
L(d, 1, n / 2) {
p[d * 2 - 1] = d * 2 + 1;
p[d * 2] = d * 2 - 1;
if(1 < d && d < n / 2) {
--p[d * 2];
}
if(d == n / 2)
--p[d * 2], --p[d * 2 - 1];
}
if(n % 2)p[n] = n;
}
Gen();
if(cnt == k)return prt();
int Lun = (n + 3) / 3;
int g = sqrt(k) * 4;
g = min(g, n - 2);
L(d, 1, Lun){
int lst = cnt;
if(orz() % 2 == 0) {
int d = rad(1, g);
if(orz() & 1) d = n - 1 - d;
swap(p[d], p[d + 1]), swap(p[d + 1], p[d + 2]);
upm(d, d + 2);
if(!update(lst, cnt)) {
swap(p[d + 1], p[d + 2]), swap(p[d], p[d + 1]);
upm(d, d + 2);
}
}else {
int d = rad(1, g);
if(orz() & 1) d = n - 1 - d;
swap(p[d + 1], p[d + 2]), swap(p[d], p[d + 1]);
upm(d, d + 2);
if(!update(lst, cnt)) {
swap(p[d], p[d + 1]), swap(p[d + 1], p[d + 2]);
upm(d, d + 2);
}
}
if(cnt == k) {
Gen();
cout << cnt << ' ' << k << endl;
cout << "YES\n";
L(i, 1, n) cout << p[i] << ' ';
cout << '\n';
return;
}
}
mini_solve(tn, tm);
}
bitset < N > dm[N], shan[N];
int ts;
void islv(int tn, int tm) {
n = tn;
k = tm;
auto dfs = [&] (auto self, int x, int cur) {
if(cur < 0)return 0;
int con = n * (n - 1) / 2 - (x - 1) * (x - 2) / 2 - max(n - x - 1, 0) / 2;
if(cur > con)return 0;
if(x == n + 1) {
cout << "YES\n";
L(i, 1, n) cout << p[i] << ' ';
cout << '\n';
Gen();
return 1;
}
dm[x] = dm[x - 1];
bitset < N > add;
R(i, x, max(1, x - 4)) {
if(i < x) {
int pos = 0;
R(j, x - 1, 1) {
if(p[j] == i) {
pos = j;
break;
}
}
add.set(pos);
++p[pos];
dm[x] ^= shan[pos];
}
p[x] = i;
int cmll = cur - dm[x].count();
if(self(self, x + 1, cmll)) return 1;
}
for(int d = add._Find_first(); d <= n; d = add._Find_next(d))
--p[d];
return 0;
};
if(dfs(dfs, 1, k)) {
} else {
cout << "NO\n";
}
}
int main() {
ios :: sync_with_stdio(false);
cin.tie(0); cout.tie(0);
L(i, 1, 1000) {
shan[i] = shan[i - 1];
shan[i].set(i);
}
int t;
cin >> t;
while(t--) {
int n, m;
cin >> n >> m;
int mxm = n * (n - 1) / 2 - n / 2;
if(mxm - m <= n || n <= 8) {
islv(n, m);
} else if(m < n) {
mini_solve(n, m);
} else {
solve(n, m);
}
}
return 0;
cin >> n;
L(i, 1, n) {
p[i] = i;
}
do {
Gen();
int cnt = 0;
L(i, 1, n) {
L(j, i + 1, n) {
cnt += h[i][j];
}
}
if(n*(n-1)/2-n/2-cnt<=3){
L(i, 1, n) {
L(j, 1, n) {
if(j <= i) cout << " ";
else cout << (p[i] > p[j]); // h[i][j];
}
cout << endl;
}
L(i,1,n)cout<<p[i]<<' ';
cout<<":"<<cnt<<endl;
cout<<endl;
}
vis[cnt] = 1;
} while(next_permutation(p + 1, p + n + 1));
// int gm=0;
// L(i, 0, n * (n - 1) / 2) {
// if(!vis[i])++gm;
//// cout<<vis[i];
// if(vis[i]) {
// L(d, 1, n) {
// p[d] = V[i][d - 1];
// }
// Gen();
// L(i, 1, n) {
// L(j, 1, n) {
// if(j <= i) cout << " ";
// else cout << (p[i] > p[j]); // h[i][j];
// }
// cout << endl;
// }
// for(auto&p : V[i]){
// cout << p << ' ';
// }
// cout << endl;
// cout << i << endl;
// cout << endl;
// }
// }
// cout<<gm<<endl;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3732kb
input:
4 1 0 3 3 4 1 6 15
output:
YES 1 YES 3 2 1 YES 1 3 4 2 NO
result:
ok Correct (4 test cases)
Test #2:
score: -100
Wrong Answer
time: 142ms
memory: 4132kb
input:
5951 27 255 28 371 31 320 33 201 32 199 31 108 15 78 27 32 24 268 20 4 14 82 29 202 33 85 26 104 31 380 27 330 20 140 29 192 21 63 17 89 20 41 32 444 20 76 27 114 33 330 26 249 33 301 24 87 25 72 14 49 25 281 21 58 15 48 16 19 14 0 22 175 11 7 30 43 31 259 22 112 12 30 30 111 33 268 30 287 19 150 15...
output:
YES 3 6 4 5 1 2 7 8 13 11 9 15 12 17 14 10 23 19 21 16 25 18 22 20 26 24 27 NO YES 7 4 3 2 1 5 9 6 11 13 10 8 15 12 17 14 19 16 21 23 20 18 29 25 22 27 24 28 26 30 31 YES 1 2 3 4 9 7 6 5 8 11 10 12 15 16 13 17 19 21 20 24 14 18 22 23 25 26 27 30 28 33 32 31 29 YES 3 1 2 4 11 5 6 12 9 7 10 14 18 1...
result:
wrong answer Token parameter [name=yes/no] equals to "4", doesn't correspond to pattern "[yY][eE][sS]|[nN][oO]" (test case 10)