QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#212881 | #2598. Permutation Matrix | Days_of_Future_Past# | AC ✓ | 64ms | 12220kb | C++14 | 2.1kb | 2023-10-13 21:59:08 | 2023-10-13 21:59:08 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1033;
int used[99], a[N][N], s[N][N];
LL fastpo(LL x, LL n, LL mod) {
LL res = 1;
while(n) {
if(n & 1) res = res * x % mod;
x = x * x % mod;
n /= 2;
}
return res;
}
bool dfs(int v) {
if(v == 16) {
return true;
}else {
int x = v / 4;
int y = v % 4;
for(int i = 0; i < 16; i++) {
if(!used[i]) {
a[x][y] = i;
if(x >= 1 && y >= 2 && a[x][y] + a[x - 1][y] != a[x][y - 2] + a[x - 1][y - 2]) continue;
if(x >= 2 && y >= 1 && a[x][y] + a[x][y - 1] != a[x - 2][y] + a[x - 2][y - 1]) continue;
used[i] = true;
if(dfs(v + 1)) {
return true;
}
used[i] = false;
}
}
}
return false;
}
int main() {
int n;
scanf("%d", &n);
if(n == 1) {
printf("NO\n");
exit(0);
}
dfs(0);
for(int i = 3; i <= n; i++) {
for(int x = (1 << (i - 1)) - 1; x >= 0; x--) {
for(int y = (1 << (i - 1)) - 1; y >= 0; y--) {
a[x * 2][y * 2] = a[x][y] * 4;
a[x * 2][y * 2 + 1] = a[x][y] * 4 + 1;
a[x * 2 + 1][y * 2] = a[x][y] * 4 + 2;
a[x * 2 + 1][y * 2 + 1] = a[x][y] * 4 + 3;
}
}
}
printf("YES\n");
for(int i = 0; i < (1 << n); i++) {
for(int j = 0; j < (1 << n); j++) {
printf("%d%c", a[i][j] + 1, j == (1 << n) - 1 ? '\n' : ' ');
}
}
for(int i = 0; i < (1 << n); i++) {
for(int j = 0; j < (1 << n); j++) {
s[i + 1][j + 1] = s[i][j + 1] + s[i + 1][j] - s[i][j] + a[i][j];
}
}
int l = (1 << n) / 2;
LL eq = -1;
for(int i = 0; i < l; i++) {
for(int j = 0; j < l; j++) {
LL val = s[i + l][j + l] - s[i][j + l] - s[i + l][j] + s[i][j];
if(eq == -1) eq = val; else assert(eq == val);
}
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3904kb
input:
1
output:
NO
result:
ok OK.
Test #2:
score: 0
Accepted
time: 7ms
memory: 5844kb
input:
2
output:
YES 1 4 5 8 13 16 9 12 2 3 6 7 14 15 10 11
result:
ok OK.
Test #3:
score: 0
Accepted
time: 7ms
memory: 6056kb
input:
3
output:
YES 1 2 13 14 17 18 29 30 3 4 15 16 19 20 31 32 49 50 61 62 33 34 45 46 51 52 63 64 35 36 47 48 5 6 9 10 21 22 25 26 7 8 11 12 23 24 27 28 53 54 57 58 37 38 41 42 55 56 59 60 39 40 43 44
result:
ok OK.
Test #4:
score: 0
Accepted
time: 7ms
memory: 6020kb
input:
4
output:
YES 1 2 5 6 49 50 53 54 65 66 69 70 113 114 117 118 3 4 7 8 51 52 55 56 67 68 71 72 115 116 119 120 9 10 13 14 57 58 61 62 73 74 77 78 121 122 125 126 11 12 15 16 59 60 63 64 75 76 79 80 123 124 127 128 193 194 197 198 241 242 245 246 129 130 133 134 177 178 181 182 195 196 199 200 243 244 247 248 1...
result:
ok OK.
Test #5:
score: 0
Accepted
time: 7ms
memory: 6092kb
input:
5
output:
YES 1 2 5 6 17 18 21 22 193 194 197 198 209 210 213 214 257 258 261 262 273 274 277 278 449 450 453 454 465 466 469 470 3 4 7 8 19 20 23 24 195 196 199 200 211 212 215 216 259 260 263 264 275 276 279 280 451 452 455 456 467 468 471 472 9 10 13 14 25 26 29 30 201 202 205 206 217 218 221 222 265 266 2...
result:
ok OK.
Test #6:
score: 0
Accepted
time: 7ms
memory: 6296kb
input:
6
output:
YES 1 2 5 6 17 18 21 22 65 66 69 70 81 82 85 86 769 770 773 774 785 786 789 790 833 834 837 838 849 850 853 854 1025 1026 1029 1030 1041 1042 1045 1046 1089 1090 1093 1094 1105 1106 1109 1110 1793 1794 1797 1798 1809 1810 1813 1814 1857 1858 1861 1862 1873 1874 1877 1878 3 4 7 8 19 20 23 24 67 68 71...
result:
ok OK.
Test #7:
score: 0
Accepted
time: 8ms
memory: 6480kb
input:
7
output:
YES 1 2 5 6 17 18 21 22 65 66 69 70 81 82 85 86 257 258 261 262 273 274 277 278 321 322 325 326 337 338 341 342 3073 3074 3077 3078 3089 3090 3093 3094 3137 3138 3141 3142 3153 3154 3157 3158 3329 3330 3333 3334 3345 3346 3349 3350 3393 3394 3397 3398 3409 3410 3413 3414 4097 4098 4101 4102 4113 411...
result:
ok OK.
Test #8:
score: 0
Accepted
time: 11ms
memory: 8968kb
input:
8
output:
YES 1 2 5 6 17 18 21 22 65 66 69 70 81 82 85 86 257 258 261 262 273 274 277 278 321 322 325 326 337 338 341 342 1025 1026 1029 1030 1041 1042 1045 1046 1089 1090 1093 1094 1105 1106 1109 1110 1281 1282 1285 1286 1297 1298 1301 1302 1345 1346 1349 1350 1361 1362 1365 1366 12289 12290 12293 12294 1230...
result:
ok OK.
Test #9:
score: 0
Accepted
time: 17ms
memory: 10060kb
input:
9
output:
YES 1 2 5 6 17 18 21 22 65 66 69 70 81 82 85 86 257 258 261 262 273 274 277 278 321 322 325 326 337 338 341 342 1025 1026 1029 1030 1041 1042 1045 1046 1089 1090 1093 1094 1105 1106 1109 1110 1281 1282 1285 1286 1297 1298 1301 1302 1345 1346 1349 1350 1361 1362 1365 1366 4097 4098 4101 4102 4113 411...
result:
ok OK.
Test #10:
score: 0
Accepted
time: 64ms
memory: 12220kb
input:
10
output:
YES 1 2 5 6 17 18 21 22 65 66 69 70 81 82 85 86 257 258 261 262 273 274 277 278 321 322 325 326 337 338 341 342 1025 1026 1029 1030 1041 1042 1045 1046 1089 1090 1093 1094 1105 1106 1109 1110 1281 1282 1285 1286 1297 1298 1301 1302 1345 1346 1349 1350 1361 1362 1365 1366 4097 4098 4101 4102 4113 411...
result:
ok OK.