QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#493192 | #4912. WereYouLast | CloudWings | 100 ✓ | 6183ms | 5124kb | C++14 | 1.1kb | 2024-07-26 21:16:38 | 2024-07-26 21:16:38 |
Judging History
answer
/*
* Time Spent:
0. Expect: min
1. Idea:
2. Code:
* Solution:
Tag:
https://www.cnblogs.com/CloudWings/p/18324122
* Summary:
*/
bool query (int);
void modify (int, bool);
bool WereYouLast (int n, int m) {
if (m == 10) { // 只有 10 位不够维护奇偶性,但是题目允许每次修改 10 个 bit,那就直接维护 n 了
int pos = 0;
for (int i = 1; i <= m; i++)
pos = (pos<<1) | query(i);
if (++pos == n) return 1;
for (int i = m; i && pos; i--, pos >>= 1)
modify(i, pos & 1);
return 0;
}
int len = 0, pos = 0;
while (n) len++, n >>= 1;
len--;
for (int i = 1; i <= 5; i++)
pos = (pos<<1) | query(i);
if (++pos == (1<<5)) return 1;
if (query(5+pos)) {
modify(5+pos, 0);
int t = pos;
for (int i = 5; i && t; i--, t >>= 1)
modify(i, t&1);
} else {
if (pos == len) { // 第 n-1 次打个特殊标记。
for (int i = 1; i <= 5; i++)
modify(i, 1);
} else {
modify(5+pos, 1);
for (int i = 1; i <= 5; i++)
modify(i, 0);
}
}
return 0;
}
/*
g++ _1.cpp -o _1 -O2 -std=c++11 -DLOCAL; ./_1.exe
*/
详细
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 1ms
memory: 3816kb
input:
1024 10
output:
12345876 10 10
result:
ok Correct Answer. C1 = 10. C2 = 10.
Subtask #2:
score: 20
Accepted
Test #2:
score: 20
Accepted
time: 3ms
memory: 4932kb
input:
65536 100000
output:
12345876 6 6
result:
ok Correct Answer. C1 = 6. C2 = 6.
Subtask #3:
score: 30
Accepted
Test #3:
score: 30
Accepted
time: 90ms
memory: 4912kb
input:
1048576 100000
output:
12345876 6 6
result:
ok Correct Answer. C1 = 6. C2 = 6.
Subtask #4:
score: 40
Accepted
Test #4:
score: 40
Accepted
time: 6183ms
memory: 5124kb
input:
67108864 100000
output:
12345876 6 6
result:
ok Correct Answer. C1 = 6. C2 = 6.