QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#573303 | #7940. Impossible Numbers | HuTao | WA | 5ms | 21012kb | C++14 | 4.2kb | 2024-09-18 18:05:39 | 2024-09-18 18:05:40 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, M = 115, T = 2e7 + 5, m = 10;
struct BigNumber{
int n, pos;
char s[M];
inline void Write()
{
reverse(s, s + n);
for(int i = 0; i < n; i ++ ) s[i] ^= 48;
printf("%s ", s);
reverse(s, s + n);
for(int i = 0; i < n; i ++ ) s[i] ^= 48;
}
inline void Make(BigNumber &t, int i, int x)
{
for(int j = 0; j < i; j ++ ) s[j] = t.s[j];
s[i] = x;
for(int j = i; j < t.n; j ++ ) s[j + 1] = t.s[j];
n = t.n + 1, pos = min(n - 1, i + 1);
}
inline bool operator <= (const BigNumber &w) const
{
for(int i = n - 1; i >= 0; i -- )
if(s[i] != w.s[i])
return s[i] < w.s[i];
return 1;
}
inline bool operator != (const BigNumber &w) const
{
for(int i = 0; i < n; i ++ )
if(s[i] != w.s[i])
return 1;
return 0;
}
};
bool ST;
int n, k;
bitset<M> vis[m];
int f[N], st[N];
BigNumber s[N * 2], s0[N], s1[N], r0[N], r1[N], cur;
int p0, p00, p01, p10, p11, c10, c11;
struct Node{
unsigned t : 18;
unsigned i : 8;
unsigned x : 4;
}x[T], y[T];
int cnt[N];
bool ED;
inline int GetBit(Node &x, int i)
{
return i < x.i ? s[x.t].s[i] : (i == x.i ? x.x : s[x.t].s[i - 1]);
}
inline int GetBlock(Node &x, int i)
{
return ((((GetBit(x, i + 4) * 10 + GetBit(x, i + 3)) * 10) + GetBit(x, i + 2)) * 10 + GetBit(x, i + 1)) * 10 + GetBit(x, i);
}
inline void Sort(int n, int m)
{
if(!m) return ;
int c = 0;
for(int p = 1; p < 10; p ++ )
{
for(int i = 0; i < m; i ++ )
for(int j = s[i].pos; j < n; j ++ )
{
if(j == n - 1)
{
if(j == s[i].pos || s[i].s[j - 1] != p)
x[c].t = i, x[c].i = j, x[c].x = p, c ++ ;
}
else if(s[i].s[n - 2] == p)
{
for(int k = 0; k < 10; k ++ )
if(j == s[i].pos || s[i].s[j - 1] != k)
x[c].t = i, x[c].i = j, x[c].x = k, c ++ ;
}
}
if(c >= k) break;
}
// puts("\n#");
// for(int i = 0; i < c; i ++ )
// {
// cur.Make(s[x[i].t], x[i].i, x[i].x);
// cur.Write();
// }
// if(n == 4) exit(0);
Node *p = x, *q = y;
for(int i = 0; i < n; i += 5)
{
for(int j = 0; j < c; j ++ ) cnt[GetBlock(p[j], i)] ++ ;
for(int j = 1; j < N; j ++ ) cnt[j] += cnt[j - 1];
for(int j = c - 1; j >= 0; j -- ) q[ -- cnt[GetBlock(p[j], i)]] = p[j];
for(int j = 0; j < N; j ++ ) cnt[j] = 0;
swap(p, q);
}
c10 = c11 = 0;
for(int i = 0; i < c; i ++ )
{
cur.Make(s[p[i].t], p[i].i, p[i].x);
if(cur.s[n - 1])
{
if((c10 <= k && !c10) || r0[c10 - 1] != cur)
r0[c10 ++ ] = cur;
}
else
{
if((c11 <= k && !c11) || r1[c11 - 1] != cur)
r1[c11 ++ ] = cur;
}
}
// puts("\n*");
// for(int i = 0; i < c10; i ++ ) r0[i].Write();
// puts("");
// if(n == 4) exit(0);
}
inline void DFS(int i, int S)
{
if(!st[S] || p00 == k) return ;
if(i < 0)
{
if(cur.s[cur.n - 1])
{
while(p10 < c10 && p00 < k && r0[p10] <= cur) s0[p00 ++ ] = r0[p10 ++ ];
if(!p00 || (p00 < k && s0[p00 - 1] != cur)) s0[p00 ++ ] = cur;
}
else
{
while(p11 < c11 && p01 < k && r1[p11] <= cur) s1[p01 ++ ] = r1[p11 ++ ];
if(!p01 || (p01 < k && s1[p01 - 1] != cur)) s1[p01 ++ ] = cur;
}
return ;
}
for(int j = 0; j < m; j ++ )
{
cur.s[i] = j;
DFS(i - 1, S | (1 << j));
}
}
int main()
{
scanf("%d%d", &n, &k);
for(int i = 0; i < n; i ++ )
for(int j = 0; j < 6; j ++ )
{
int x;
scanf("%d", &x);
vis[x].set(i);
}
for(int i = 0; i < 1 << m; i ++ )
{
bitset<M> mask;
mask.reset();
for(int j = 0; j < m; j ++ )
if(i >> j & 1)
mask |= vis[j];
f[i] = mask.count() + 1;
}
for(int i = 1; k; i ++ )
{
Sort(i, p0);
for(int j = (1 << m) - 1; j >= 0; j -- )
{
st[j] |= f[j] <= i;
for(int k = 0; k < m; k ++ )
st[j] |= st[j | 1 << k];
}
p00 = p01 = p10 = p11 = 0;
cur.n = i, cur.pos = 0;
DFS(i - 1, 0);
while(p10 < c10 && p00 < k) s0[p00 ++ ] = r0[p10 ++ ];
while(p11 < c11 && p01 < k) s1[p01 ++ ] = r1[p11 ++ ];
for(int i = 0; i < p00; i ++ ) s0[i].Write();
k -= p00;
for(int i = 0; i < p00; i ++ ) s[i] = s0[i];
for(int i = 0; i < p01; i ++ ) s[i + p00] = s1[i];
p0 = p00 + p01;
}
puts("");
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 12252kb
input:
2 3 1 8 7 0 6 2 1 2 5 4 9 3
output:
33 34 35
result:
ok single line: '33 34 35 '
Test #2:
score: 0
Accepted
time: 2ms
memory: 12704kb
input:
1 10 1 5 2 2 6 4
output:
3 7 8 9 10 11 12 13 14 15
result:
ok single line: '3 7 8 9 10 11 12 13 14 15 '
Test #3:
score: 0
Accepted
time: 0ms
memory: 12820kb
input:
4 10 1 5 7 1 2 4 0 1 5 8 9 4 3 5 2 2 7 8 6 1 7 0 2 2
output:
33 66 99 133 166 199 233 266 299 303
result:
ok single line: '33 66 99 133 166 199 233 266 299 303 '
Test #4:
score: 0
Accepted
time: 2ms
memory: 10772kb
input:
5 10 5 9 4 8 3 3 1 1 9 2 8 9 6 3 3 0 2 1 2 6 0 3 6 4 3 6 4 2 9 4
output:
7 17 27 37 47 55 57 67 70 71
result:
ok single line: '7 17 27 37 47 55 57 67 70 71 '
Test #5:
score: 0
Accepted
time: 0ms
memory: 12772kb
input:
5 10 8 7 1 4 8 9 2 5 0 1 0 1 9 5 5 3 9 7 6 0 0 2 3 1 1 0 0 4 9 3
output:
66 88 166 188 222 226 262 266 288 366
result:
ok single line: '66 88 166 188 222 226 262 266 288 366 '
Test #6:
score: 0
Accepted
time: 0ms
memory: 10928kb
input:
5 10 6 8 7 7 0 0 0 5 1 9 4 1 5 9 6 9 5 4 0 4 6 9 1 6 2 8 7 4 4 0
output:
3 13 22 23 30 31 32 33 34 35
result:
ok single line: '3 13 22 23 30 31 32 33 34 35 '
Test #7:
score: 0
Accepted
time: 3ms
memory: 12716kb
input:
5 1000 0 4 1 3 9 6 9 6 2 1 8 6 5 3 0 7 7 3 0 2 8 0 8 4 2 4 1 2 9 7
output:
55 155 255 333 335 353 355 455 505 515 525 533 535 545 550 551 552 553 554 555 556 557 558 559 565 575 577 585 595 655 666 755 757 775 777 855 888 955 1055 1111 1116 1119 1155 1161 1166 1169 1191 1196 1199 1255 1333 1335 1353 1355 1455 1505 1515 1525 1533 1535 1545 1550 1551 1552 1553 1554 1555 1556...
result:
ok single line: '55 155 255 333 335 353 355 455... 10053 10055 10111 10116 10119 '
Test #8:
score: 0
Accepted
time: 5ms
memory: 21012kb
input:
5 10000 1 4 7 5 6 0 2 3 8 4 9 0 1 2 8 8 3 0 7 9 9 7 2 9 4 7 1 9 3 6
output:
55 155 255 355 455 505 515 525 535 545 550 551 552 553 554 555 556 557 558 559 565 566 575 585 595 655 656 665 666 755 855 888 955 1055 1111 1115 1116 1151 1155 1156 1161 1165 1166 1255 1355 1455 1505 1511 1515 1516 1525 1535 1545 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1561 1565 1566 1575...
result:
ok single line: '55 155 255 355 455 505 515 525... 45507 45508 45509 45510 45511 '
Test #9:
score: 0
Accepted
time: 0ms
memory: 18964kb
input:
6 10000 0 1 3 2 4 7 7 6 4 8 7 9 5 5 7 2 3 9 8 4 6 1 6 4 2 4 9 9 0 7 1 2 3 3 2 0
output:
55 155 255 355 455 505 515 525 535 545 550 551 552 553 554 555 556 557 558 559 565 575 585 595 655 666 668 686 688 755 855 866 868 886 888 955 1055 1111 1155 1255 1355 1455 1505 1515 1525 1535 1545 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1565 1575 1585 1595 1655 1666 1668 1686 1688 1755 18...
result:
ok single line: '55 155 255 355 455 505 515 525... 66847 66848 66849 66850 66851 '
Test #10:
score: -100
Wrong Answer
time: 2ms
memory: 12744kb
input:
7 1000 5 2 1 6 3 7 7 9 8 1 8 1 8 7 2 0 6 2 3 8 6 0 5 1 8 8 3 7 0 8 1 0 6 3 5 6 6 7 5 0 9 1
output:
4 14 24 34 40 41 42 43 44 45 46 47 48 49 54 64 74 84 94 104 114 124 134 140 141 142 143 144 145 146 147 148 149 154 164 174 184 194 204 214 222 224 234 240 241 242 243 244 245 246 247 248 249 254 264 274 284 294 304 314 324 334 340 341 342 343 344 345 346 347 348 349 354 364 374 384 394 400 401 402 ...
result:
wrong answer 1st lines differ - expected: '4 14 24 34 40 41 42 43 44 45 4...3 3474 3475 3476 3477 3478 3479', found: '4 14 24 34 40 41 42 43 44 45 4... 10452 10453 10454 10455 10456 '