QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#687835 | #9519. Build a Computer | ucup-team2526 | AC ✓ | 1ms | 3880kb | C++20 | 7.0kb | 2024-10-29 21:31:25 | 2024-10-29 21:31:25 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define dbg(x...) \
do { \
cout << #x << " -> "; \
err(x); \
} while (0)
void err() {
cout << endl << endl;
}
template <class T, class... Ts>
void err(T arg, Ts... args) {
cout << fixed << setprecision(10) << arg << ' ';
err(args...);
}
vector<pair<int, int> > t[100];
int vis[100][100][2];
int to[105], tot, num1[100];
int du[105],l,r,cur;
vector<int> get(int x) {
vector<int> ans;
while (x) {
ans.push_back(x % 2);
x /= 2;
}
reverse(ans.begin(), ans.end());
return ans;
}
void link(int pre_node, int node,int val) {
if (pre_node == -1) {
pre_node = 0;
if (vis[pre_node][node][val]) return;
//du[node]++;
t[0].push_back({node, val});
vis[pre_node][node][val] = 1;
} else {
if (vis[pre_node][node][val]) return;
//du[node]++;
t[pre_node].push_back({node, val});
vis[pre_node][node][val] = 1;
}
}
void solve1() {
for (int i = l; i <= r; i++) {
vector<int> num = get(i);
int len = num.size();
int pre_node = 0,node;
for (int j = 1; j < len; j++) {
int step = 20 - len + j;
int pre = num[j - 1], now = num[j];
//dbg(step,i,pre,now);
if (pre == 0 && now == 0) {
node = (step - 1) * 4 + 4;
link(pre_node, node, pre);
} else if (pre == 0 && now == 1) {
node = (step - 1) * 4 + 3;
link(pre_node, node, pre);
} else if (pre == 1 && now == 0) {
node = (step - 1) * 4 + 2;
link(pre_node, node, pre);
} else {
node = (step - 1) * 4 + 1;
link(pre_node, node, pre);
}
pre_node = node;
}
link(pre_node,81,num[len - 1]);
}
// for (int i = 0; i <= 81; i++) {
// if (!t[i].empty() || i == 81) {
// //if (du[i] == 0 && i != 0) while (1);
// tot++;
// to[tot] = i;
// num1[i] = tot;
// }
// }
queue<int>q;
q.push(0);
while (!q.empty()) {
int now = q.front();
q.pop();
if (num1[now] == 0) num1[now] = ++tot,to[tot] = now;
else continue;
for (auto i : t[now]) {
q.push(i.first);
}
}
cout << tot << '\n';
for (int i = 1; i <= tot; i++) {
cout << t[to[i]].size() << ' ';
for (auto j : t[to[i]]) cout << num1[j.first] << ' ' << j.second << ' ';
cout << '\n';
}
return;
}
void solve() {
cin >> l >> r;
vector <int> numl = get(l),numr = get(r);
if (l == r) {
cout << numl.size() + 1 << '\n';
for (int i = 0; i < (int)numl.size(); i++) {
cout << i + 1 << ' ' << i + 2 << ' ' << numl[i] << '\n';
}
cout << 0 << '\n';
return ;
}
if (numl.size() == numr.size()) {
for (int i = 1; i < 20; i++) {
t[i].push_back({i + 1,0});
t[i].push_back({i + 1,1});
}
t[20].push_back({22,0});
t[20].push_back({22,1});
int st = 21,ed = 22,cur = 23,p = numl.size() - 1;
for (int i = 0; i < (int)numl.size(); i++) {
if (numl[i] == 0 && numr[i] == 1) {
p = i - 1;
break;
}
}
int pre = st,lenl = numl.size(),pos = -1;
//dbg(p);
for (int i = 0; i <= p; i++) {
if (i == lenl - 1) {
t[pre].push_back({ed,0});
t[pre].push_back({ed,1});
break;
}
t[pre].push_back({cur,numl[i]});
pre = cur;
cur++;
pos = pre;
}
for (int i = 1; i < lenl - p - 1; i++) {
int val = numl[i + p];
t[pre].push_back({cur,val});
if (val == 0 && i != 1) {
t[pre].push_back({cur + 1,1});
int numm = 20 - lenl + (i + p) + 3;
if (numm == 21) numm = 22;
//dbg()
t[cur + 1].push_back({numm,0});
t[cur + 1].push_back({numm,1});
pre = cur;
cur += 2;
continue;
}
pre = cur;
cur++;
}
int v = numl[lenl - 1];
if (v == 0) {
if (lenl - p - 1 == 1) {
t[pre].push_back({ed,0});
}
else {
t[pre].push_back({ed,1});
t[pre].push_back({ed,0});
}
} else {
t[pre].push_back({ed,1});
}
pre = pos;
for (int i = 1; i < lenl - p - 1; i++) {
int val = numr[i + p];
t[pre].push_back({cur,val});
if (val == 1 && i != 1) {
t[pre].push_back({cur + 1,0});
int numm = 20 - lenl + (i + p) + 3;
if (numm == 21) numm = 22;
//dbg()
t[cur + 1].push_back({numm,0});
t[cur + 1].push_back({numm,1});
pre = cur;
cur += 2;
continue;
}
pre = cur;
cur++;
}
v = numr[lenl - 1];
if (v == 1) {
if (lenl - p - 1 == 1) {
t[pre].push_back({ed,1});
}
else {
t[pre].push_back({ed,1});
t[pre].push_back({ed,0});
}
} else {
t[pre].push_back({ed,0});
}
map<int,int>mp;
int zhi = 1;
int now = st;
queue<int>q;
q.push(now);
while (!q.empty()) {
auto u = q.front();
q.pop();
if (mp[u]) continue;
mp[u] = zhi;
to[zhi] = u;
zhi++;
for (auto i : t[u]) {
q.push(i.first);
}
}
cout << mp.size() << '\n';
for (int i = 1; i <= (int)mp.size(); i++) {
cout << t[to[i]].size() << ' ';
for (auto j : t[to[i]]) {
cout << mp[j.first] << ' ' << j.second << ' ';
}
cout << '\n';
}
return ;
}
for (int i = 1; i < 20; i++) {
t[i].push_back({i + 1,0});
t[i].push_back({i + 1,1});
}
t[20].push_back({22,0});
t[20].push_back({22,1});
int st = 21,ed = 22,cur = 23;
int lenl = numl.size();
int pre = st;
for (int i = 0; i < lenl - 1; i++) {
int val = numl[i];
t[pre].push_back({cur,val});
if (val == 0) {
t[pre].push_back({cur + 1,1});
int numm = 20 - lenl + i + 3;
if (numm == 21) numm = 22;
//dbg(numm);
t[cur + 1].push_back({numm,0});
t[cur + 1].push_back({numm,1});
pre = cur;
cur += 2;
continue;
}
pre = cur;
cur++;
}
int v = numl[lenl - 1];
if (v == 0) {
t[pre].push_back({ed,0});
t[pre].push_back({ed,1});
} else {
t[pre].push_back({ed,1});
}
int lenr = numr.size();
pre = st;
for (int i = lenl + 1; i <= lenr - 1; i++) {
//dbg(20 - i + 3);
t[st].push_back({20 - i + 2,1});
}
for (int i = 0; i < lenr - 1; i++) {
int val = numr[i];
t[pre].push_back({cur,val});
if (val == 1 && i != 0) {
t[pre].push_back({cur + 1,0});
int numm = 20 - lenr + i + 3;
if (numm == 21) numm = 22;
//dbg()
t[cur + 1].push_back({numm,0});
t[cur + 1].push_back({numm,1});
pre = cur;
cur += 2;
continue;
}
pre = cur;
cur++;
}
v = numr[lenr - 1];
if (v == 1) {
t[pre].push_back({ed,0});
t[pre].push_back({ed,1});
} else {
t[pre].push_back({ed,0});
}
map<int,int>mp;
int zhi = 1;
int now = st;
queue<int>q;
q.push(now);
while (!q.empty()) {
auto u = q.front();
q.pop();
if (mp[u]) continue;
mp[u] = zhi;
to[zhi] = u;
zhi++;
for (auto i : t[u]) {
q.push(i.first);
}
}
cout << mp.size() << '\n';
for (int i = 1; i <= (int)mp.size(); i++) {
cout << t[to[i]].size() << ' ';
for (auto j : t[to[i]]) {
cout << mp[j.first] << ' ' << j.second << ' ';
}
cout << '\n';
}
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0);
int t = 1;
// cin >> t;
while (t--) solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3864kb
input:
5 7
output:
5 1 2 1 2 3 0 4 1 1 5 1 2 5 1 5 0 0
result:
ok ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
10 27
output:
14 2 2 1 3 1 2 4 0 5 1 2 6 1 7 0 1 8 1 2 9 0 9 1 1 10 0 2 11 0 11 1 2 12 0 12 1 2 12 0 12 1 2 13 1 14 0 2 9 0 9 1 0 2 12 0 12 1 2 12 0 12 1
result:
ok ok
Test #3:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
5 13
output:
10 2 2 1 3 1 2 4 0 5 1 2 6 1 7 0 1 8 1 2 8 0 8 1 1 9 0 2 10 0 10 1 0 2 8 0 8 1 2 8 0 8 1
result:
ok ok
Test #4:
score: 0
Accepted
time: 0ms
memory: 3872kb
input:
1 1000000
output:
45 20 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 0 2 2 0 2 1 2 3 0 3 1 2 4 0 4 1 2 5 0 5 1 2 6 0 6 1 2 7 0 7 1 2 8 0 8 1 2 9 0 9 1 2 10 0 10 1 2 11 0 11 1 2 12 0 12 1 2 13 0 13 1 2 14 0 14 1 2 15 0 15 1 2 16 0 16 1 2 17 0 17 1 2 18 0...
result:
ok ok
Test #5:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
1 1
output:
2 1 2 1 0
result:
ok ok
Test #6:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
7 9
output:
7 2 2 1 3 1 1 4 1 1 5 0 1 6 1 1 7 0 0 2 6 0 6 1
result:
ok ok
Test #7:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
3 7
output:
6 2 2 1 3 1 1 4 1 2 5 1 6 0 0 2 4 0 4 1 2 4 0 4 1
result:
ok ok
Test #8:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
1 5
output:
5 3 2 1 3 1 4 1 0 2 2 0 2 1 1 5 0 2 2 0 2 1
result:
ok ok
Test #9:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
1 4
output:
5 3 2 1 3 1 4 1 0 2 2 0 2 1 1 5 0 1 2 0
result:
ok ok
Test #10:
score: 0
Accepted
time: 0ms
memory: 3680kb
input:
8 9
output:
5 1 2 1 1 3 0 1 4 0 2 5 0 5 1 0
result:
ok ok
Test #11:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
7 51
output:
15 4 2 1 3 1 4 1 5 1 1 6 1 2 7 0 7 1 2 3 0 3 1 2 8 1 9 0 1 10 1 2 11 0 11 1 1 12 0 2 3 0 3 1 0 2 10 0 10 1 1 13 0 2 14 1 15 0 2 10 0 10 1 2 10 0 10 1
result:
ok ok
Test #12:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
51 79
output:
20 2 2 1 3 1 1 4 1 1 5 0 2 6 0 7 1 1 8 0 2 9 0 10 1 2 11 0 11 1 2 12 1 13 0 1 14 1 2 15 0 15 1 2 15 0 15 1 2 16 1 17 0 2 11 0 11 1 1 18 1 2 18 0 18 1 2 19 1 20 0 2 15 0 15 1 0 2 18 0 18 1 2 18 0 18 1
result:
ok ok
Test #13:
score: 0
Accepted
time: 1ms
memory: 3580kb
input:
92 99
output:
15 1 2 1 2 3 0 4 1 1 5 1 1 6 0 1 7 1 1 8 0 1 9 1 1 10 0 2 11 0 12 1 2 13 1 14 0 2 15 1 15 0 2 15 0 15 1 2 15 1 15 0 2 15 0 15 1 0
result:
ok ok
Test #14:
score: 0
Accepted
time: 0ms
memory: 3880kb
input:
27 36
output:
14 2 2 1 3 1 1 4 1 1 5 0 2 6 0 7 1 1 8 0 1 9 1 2 10 0 10 1 2 11 1 12 0 1 13 1 2 13 0 13 1 1 14 0 2 10 0 10 1 0 1 13 0
result:
ok ok
Test #15:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
55 84
output:
19 2 2 1 3 1 1 4 1 1 5 0 2 6 0 7 1 2 8 1 9 0 1 10 1 2 11 0 11 1 1 12 0 2 13 0 13 1 1 14 1 2 15 0 15 1 2 16 1 17 0 2 11 0 11 1 1 18 1 2 18 0 18 1 1 19 0 2 15 0 15 1 0 1 18 0
result:
ok ok
Test #16:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
297208 929600
output:
74 2 2 1 3 1 2 4 0 5 1 2 6 1 7 0 2 8 0 9 1 2 10 0 10 1 2 11 1 12 0 2 13 0 13 1 1 14 1 2 15 0 15 1 2 15 0 15 1 1 16 0 2 10 0 10 1 2 10 0 10 1 2 17 0 18 1 2 19 0 19 1 1 20 0 2 21 0 22 1 2 23 0 23 1 2 23 0 23 1 1 24 0 2 25 0 26 1 2 27 0 27 1 2 27 0 27 1 2 28 1 29 0 1 30 1 2 31 ...
result:
ok ok
Test #17:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
45728 589156
output:
73 5 2 1 3 1 4 1 5 1 6 1 2 7 0 8 1 2 9 0 9 1 2 3 0 3 1 2 4 0 4 1 1 10 0 1 11 1 2 12 0 12 1 2 13 0 13 1 1 14 0 1 15 1 2 16 0 16 1 2 12 0 12 1 1 17 0 2 18 0 19 1 2 20 0 20 1 2 21 1 22 0 2 23 0 24 1 2 25 0 25 1 2 25 0 25 1 2 26 1 27 0 2 13 0 13 1 1 28 1 2 29 0 29 1 2 29 0 29 1 ...
result:
ok ok
Test #18:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
129152 138000
output:
60 2 2 1 3 1 1 4 1 1 5 0 1 6 1 1 7 0 1 8 1 1 9 0 1 10 1 1 11 0 1 12 1 2 13 1 14 0 2 15 0 16 1 2 17 1 18 0 2 19 0 19 1 2 20 0 21 1 2 22 0 22 1 1 23 0 2 24 0 24 1 2 24 0 24 1 2 25 0 26 1 2 27 0 27 1 2 27 0 27 1 2 28 1 29 0 2 22 0 22 1 1 30 1 2 31 0 31 1 2 31 0 31 1 2 32 1 33...
result:
ok ok
Test #19:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
245280 654141
output:
76 3 2 1 3 1 4 1 1 5 1 2 6 0 6 1 1 7 0 1 8 1 2 9 0 9 1 1 10 0 2 11 0 12 1 2 13 0 13 1 2 14 1 15 0 1 16 1 2 17 0 17 1 2 18 0 18 1 2 19 1 20 0 2 13 0 13 1 1 21 1 2 22 0 22 1 2 17 0 17 1 2 23 1 24 0 2 18 0 18 1 1 25 1 2 26 0 26 1 2 27 1 28 0 2 17 0 17 1 1 29 1 2 30 0 30 1 2 31...
result:
ok ok
Test #20:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
202985 296000
output:
63 2 2 1 3 1 1 4 1 1 5 0 2 6 0 7 1 1 8 0 2 9 0 10 1 2 11 0 11 1 2 12 1 13 0 2 14 0 15 1 2 16 0 16 1 2 16 0 16 1 1 17 0 2 11 0 11 1 1 18 1 2 19 0 19 1 2 19 0 19 1 1 20 0 1 21 1 2 22 0 22 1 1 23 0 2 24 0 25 1 2 26 0 26 1 1 27 0 2 28 0 29 1 2 30 0 30 1 2 30 0 30 1 2 31 1 32 0 ...
result:
ok ok
Test #21:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
438671 951305
output:
69 2 2 1 3 1 1 4 1 2 5 1 6 0 2 7 0 8 1 2 9 1 10 0 2 11 0 11 1 1 12 1 2 13 0 13 1 1 14 0 2 15 0 15 1 2 15 0 15 1 2 16 0 17 1 2 18 0 18 1 2 19 1 20 0 2 13 0 13 1 1 21 1 2 22 0 22 1 2 22 0 22 1 1 23 0 2 18 0 18 1 1 24 1 2 25 0 25 1 1 26 0 2 27 0 28 1 2 29 0 29 1 1 30 0 2 31 0 ...
result:
ok ok
Test #22:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
425249 739633
output:
71 2 2 1 3 1 1 4 1 1 5 0 2 6 0 7 1 2 8 1 9 0 2 10 0 11 1 2 12 0 12 1 2 13 1 14 0 2 15 0 15 1 1 16 1 2 17 0 17 1 2 17 0 17 1 1 18 0 2 12 0 12 1 2 12 0 12 1 1 19 1 2 20 0 20 1 2 21 1 22 0 1 23 1 2 24 0 24 1 1 25 0 2 20 0 20 1 1 26 1 2 27 0 27 1 1 28 0 1 29 1 2 30 0 30 1 2 31...
result:
ok ok
Test #23:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
551207 961718
output:
75 1 2 1 2 3 0 4 1 2 5 0 6 1 2 7 1 8 0 2 9 0 10 1 2 11 0 11 1 1 12 0 2 11 0 11 1 2 13 0 14 1 2 15 0 15 1 2 15 0 15 1 2 16 1 17 0 1 18 1 2 19 0 19 1 2 19 0 19 1 1 20 0 2 19 0 19 1 1 21 1 2 22 0 22 1 2 23 1 24 0 2 25 0 26 1 2 27 0 27 1 1 28 0 2 27 0 27 1 1 29 1 2 30 0 30 1 2 ...
result:
ok ok
Test #24:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
114691 598186
output:
73 4 2 1 3 1 4 1 5 1 1 6 1 2 7 0 7 1 2 3 0 3 1 1 8 0 1 9 1 2 10 0 10 1 1 11 0 2 12 0 13 1 2 14 0 14 1 2 15 1 16 0 2 17 0 18 1 2 19 0 19 1 2 20 0 20 1 1 21 0 2 10 0 10 1 2 22 0 23 1 2 24 0 24 1 2 24 0 24 1 2 19 0 19 1 1 25 0 2 26 0 27 1 2 28 0 28 1 2 28 0 28 1 2 29 1 30 0 2 3...
result:
ok ok
Test #25:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
234654 253129
output:
57 1 2 1 1 3 1 1 4 1 2 5 0 6 1 2 7 0 8 1 1 9 0 1 10 1 2 11 0 11 1 2 12 1 13 0 2 14 0 15 1 2 16 0 16 1 2 17 1 18 0 2 16 0 16 1 1 19 1 2 20 0 20 1 2 20 0 20 1 2 21 1 22 0 2 20 0 20 1 2 23 0 24 1 2 25 0 25 1 1 26 0 2 25 0 25 1 2 27 0 28 1 2 29 0 29 1 2 29 0 29 1 1 30 0 1 31 1 ...
result:
ok ok
Test #26:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
554090 608599
output:
65 1 2 1 1 3 0 1 4 0 2 5 0 6 1 2 7 0 8 1 1 9 0 1 10 1 2 11 0 11 1 2 12 1 13 0 1 14 1 2 15 0 15 1 1 16 0 2 15 0 15 1 1 17 1 2 18 0 18 1 1 19 0 2 20 0 21 1 2 22 0 22 1 2 23 1 24 0 1 25 1 2 26 0 26 1 2 26 0 26 1 1 27 0 2 26 0 26 1 2 28 0 29 1 2 30 0 30 1 1 31 0 2 32 0 33 1 2...
result:
ok ok
Extra Test:
score: 0
Extra Test Passed