QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#176748 | #6320. Parallel Processing (Hard) | ucup-team1209 | AC ✓ | 3ms | 7588kb | C++20 | 2.9kb | 2023-09-11 23:07:37 | 2023-09-11 23:07:38 |
Judging History
answer
#include<bits/stdc++.h>
using std::cin;
using std::cout;
const int N = 100005;
using vec = std::vector<int>;
using vpi = std::vector<std::pair<int, int>>;
std::map<vec, int> map;
std::map<vec, vpi> deletes;
std::map<vec, vec> nxt;
int n;
int dfs(vec x) {
if(x.empty()) return 0;
if(map.count(x)) return map[x];
int ans = 1e9;
vpi del; vec nx;
for(int i = 1;i < (1 << x.size());++i) {
if(i & i >> 1) continue;
int sum = 0;
vec z;
for(int j = 0;j < (int) x.size();++j) if(i >> j & 1) {
sum += (j == (int) x.size() - 1 ? n : x[j + 1]) - x[j];
} else {
z.push_back(x[j]);
}
int co = (sum + 3) / 4 + dfs(z);
if(co < ans) {
ans = co;
del.clear();
for(int j = 0;j < (int) x.size();++j) if(i >> j & 1) {
int nxt = j == (int) x.size() - 1 ? n : x[j + 1];
for(int k = x[j];k < nxt;++k) del.emplace_back(x[j], k + 1);
}
nx = z;
}
}
deletes[x] = del;
nxt[x] = nx;
return map[x] = ans;
}
std::string s[N];
int main() {
cin >> n;
vec v;
for(int i = 1;i < n;++i) {
v.push_back(i);
}
for(int i = 1;i <= n;++i) {
if(i < 10) s[i] = '0' + i;
else s[i] = 'a' + i - 10;
}
if(n > 16) {
std::vector<std::pair<int, int>> d;
int m = n / 5 + 1;
int pb = n % 5 == 3 || n % 5 == 4;
int P[] = { 0, m, m * 2, m * 3 + pb, m * 4 + pb * 2 };
int L[] = { m, m, m + pb, m + pb };
for(int i = 2;i <= m;++i) {
for(int j = 0;j < 4;++j) {
d.emplace_back(i - 1 + P[j], i + P[j]);
}
}
std::vector<std::pair<int, int>> free;
for(int i = 1;i < 4;++i) {
int pos = L[i] - 3;
if(pb && i == 1) {
pos = L[i] - 1;
}
for(int j = pos;j <= L[i];++j) {
d.emplace_back(P[i], P[i] + j);
}
if(pb && i == 1) {
d.emplace_back(m + P[2], m + 1 + P[2]);
d.emplace_back(m + P[3], m + 1 + P[3]);
}
for(int j = 1;j < pos;++j) {
free.emplace_back(P[i], P[i] + j);
}
}
for(int k = P[4] + 1;k <= n;++k) {
d.emplace_back(k - 1, k);
for(int x = 0;x < 3;++x) {
if(free.size()) {
d.push_back(free.back());
free.pop_back();
} else {
auto x = d.back();
d.push_back(x);
}
}
}
for(;free.size();) {
for(int x = 0;x < 4;++x) {
if(free.size()) {
d.push_back(free.back());
free.pop_back();
} else {
auto x = d.back();
d.push_back(x);
}
}
}
cout << d.size() / 4 << '\n';
for(auto [u, v] : d) {
cout << v << ' ' << u << ' ' << v << '\n';
s[v] = s[u] + s[v];
}
// for(int i = 1;i <= n;++i) cout << s[i] << '\n';
return 0;
}
dfs(v);
cout << dfs(v) << '\n';
return 0;
for(;v.size();) {
auto d = deletes[v];
for(;d.size() % 4;) d.emplace_back(2e3, 2e3);
for(auto [u, v] : d) {
cout << v << ' ' << u << ' ' << v << '\n';
s[v] = s[u] + s[v];
}
v = nxt[v];
}
// for(int i = 1;i <= n;++i) cout << s[i] << '\n';
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 6612kb
input:
17
output:
7 2 1 2 6 5 6 10 9 10 14 13 14 3 2 3 7 6 7 11 10 11 15 14 15 4 3 4 8 7 8 12 11 12 16 15 16 5 4 5 6 4 6 7 4 7 8 4 8 9 8 9 10 8 10 11 8 11 12 8 12 13 12 13 14 12 14 15 12 15 16 12 16 17 16 17 17 16 17 17 16 17 17 16 17
result:
ok AC
Test #2:
score: 0
Accepted
time: 0ms
memory: 6612kb
input:
18
output:
7 2 1 2 6 5 6 10 9 10 15 14 15 3 2 3 7 6 7 11 10 11 16 15 16 4 3 4 8 7 8 12 11 12 17 16 17 7 4 7 8 4 8 13 12 13 18 17 18 10 8 10 11 8 11 12 8 12 13 8 13 15 13 15 16 13 16 17 13 17 18 13 18 14 13 14 9 8 9 6 4 6 5 4 5
result:
ok AC
Test #3:
score: 0
Accepted
time: 0ms
memory: 6576kb
input:
19
output:
8 2 1 2 6 5 6 10 9 10 15 14 15 3 2 3 7 6 7 11 10 11 16 15 16 4 3 4 8 7 8 12 11 12 17 16 17 7 4 7 8 4 8 13 12 13 18 17 18 10 8 10 11 8 11 12 8 12 13 8 13 15 13 15 16 13 16 17 13 17 18 13 18 19 18 19 14 13 14 9 8 9 6 4 6 5 4 5 5 4 5 5 4 5 5 4 5
result:
ok AC
Test #4:
score: 0
Accepted
time: 0ms
memory: 6644kb
input:
20
output:
8 2 1 2 7 6 7 12 11 12 17 16 17 3 2 3 8 7 8 13 12 13 18 17 18 4 3 4 9 8 9 14 13 14 19 18 19 5 4 5 10 9 10 15 14 15 20 19 20 7 5 7 8 5 8 9 5 9 10 5 10 12 10 12 13 10 13 14 10 14 15 10 15 17 15 17 18 15 18 19 15 19 20 15 20 16 15 16 11 10 11 6 5 6 6 5 6
result:
ok AC
Test #5:
score: 0
Accepted
time: 0ms
memory: 6604kb
input:
21
output:
8 2 1 2 7 6 7 12 11 12 17 16 17 3 2 3 8 7 8 13 12 13 18 17 18 4 3 4 9 8 9 14 13 14 19 18 19 5 4 5 10 9 10 15 14 15 20 19 20 7 5 7 8 5 8 9 5 9 10 5 10 12 10 12 13 10 13 14 10 14 15 10 15 17 15 17 18 15 18 19 15 19 20 15 20 21 20 21 16 15 16 11 10 11 6 5 6
result:
ok AC
Test #6:
score: 0
Accepted
time: 1ms
memory: 6640kb
input:
120
output:
48 2 1 2 27 26 27 52 51 52 77 76 77 3 2 3 28 27 28 53 52 53 78 77 78 4 3 4 29 28 29 54 53 54 79 78 79 5 4 5 30 29 30 55 54 55 80 79 80 6 5 6 31 30 31 56 55 56 81 80 81 7 6 7 32 31 32 57 56 57 82 81 82 8 7 8 33 32 33 58 57 58 83 82 83 9 8 9 34 33 34 59 58 59 84 83 84 10 9 10 35 34 35 60 59 60 85 84 8...
result:
ok AC
Test #7:
score: 0
Accepted
time: 0ms
memory: 6820kb
input:
421
output:
168 2 1 2 87 86 87 172 171 172 257 256 257 3 2 3 88 87 88 173 172 173 258 257 258 4 3 4 89 88 89 174 173 174 259 258 259 5 4 5 90 89 90 175 174 175 260 259 260 6 5 6 91 90 91 176 175 176 261 260 261 7 6 7 92 91 92 177 176 177 262 261 262 8 7 8 93 92 93 178 177 178 263 262 263 9 8 9 94 93 94 179 178 ...
result:
ok AC
Test #8:
score: 0
Accepted
time: 2ms
memory: 6884kb
input:
464
output:
186 2 1 2 95 94 95 188 187 188 282 281 282 3 2 3 96 95 96 189 188 189 283 282 283 4 3 4 97 96 97 190 189 190 284 283 284 5 4 5 98 97 98 191 190 191 285 284 285 6 5 6 99 98 99 192 191 192 286 285 286 7 6 7 100 99 100 193 192 193 287 286 287 8 7 8 101 100 101 194 193 194 288 287 288 9 8 9 102 101 102 ...
result:
ok AC
Test #9:
score: 0
Accepted
time: 2ms
memory: 7320kb
input:
812
output:
325 2 1 2 165 164 165 328 327 328 491 490 491 3 2 3 166 165 166 329 328 329 492 491 492 4 3 4 167 166 167 330 329 330 493 492 493 5 4 5 168 167 168 331 330 331 494 493 494 6 5 6 169 168 169 332 331 332 495 494 495 7 6 7 170 169 170 333 332 333 496 495 496 8 7 8 171 170 171 334 333 334 497 496 497 9 ...
result:
ok AC
Test #10:
score: 0
Accepted
time: 3ms
memory: 7360kb
input:
862
output:
345 2 1 2 175 174 175 348 347 348 521 520 521 3 2 3 176 175 176 349 348 349 522 521 522 4 3 4 177 176 177 350 349 350 523 522 523 5 4 5 178 177 178 351 350 351 524 523 524 6 5 6 179 178 179 352 351 352 525 524 525 7 6 7 180 179 180 353 352 353 526 525 526 8 7 8 181 180 181 354 353 354 527 526 527 9 ...
result:
ok AC
Test #11:
score: 0
Accepted
time: 3ms
memory: 7552kb
input:
996
output:
398 2 1 2 202 201 202 402 401 402 602 601 602 3 2 3 203 202 203 403 402 403 603 602 603 4 3 4 204 203 204 404 403 404 604 603 604 5 4 5 205 204 205 405 404 405 605 604 605 6 5 6 206 205 206 406 405 406 606 605 606 7 6 7 207 206 207 407 406 407 607 606 607 8 7 8 208 207 208 408 407 408 608 607 608 9 ...
result:
ok AC
Test #12:
score: 0
Accepted
time: 0ms
memory: 7556kb
input:
997
output:
399 2 1 2 202 201 202 402 401 402 602 601 602 3 2 3 203 202 203 403 402 403 603 602 603 4 3 4 204 203 204 404 403 404 604 603 604 5 4 5 205 204 205 405 404 405 605 604 605 6 5 6 206 205 206 406 405 406 606 605 606 7 6 7 207 206 207 407 406 407 607 606 607 8 7 8 208 207 208 408 407 408 608 607 608 9 ...
result:
ok AC
Test #13:
score: 0
Accepted
time: 2ms
memory: 7528kb
input:
998
output:
399 2 1 2 202 201 202 402 401 402 603 602 603 3 2 3 203 202 203 403 402 403 604 603 604 4 3 4 204 203 204 404 403 404 605 604 605 5 4 5 205 204 205 405 404 405 606 605 606 6 5 6 206 205 206 406 405 406 607 606 607 7 6 7 207 206 207 407 406 407 608 607 608 8 7 8 208 207 208 408 407 408 609 608 609 9 ...
result:
ok AC
Test #14:
score: 0
Accepted
time: 0ms
memory: 7568kb
input:
999
output:
400 2 1 2 202 201 202 402 401 402 603 602 603 3 2 3 203 202 203 403 402 403 604 603 604 4 3 4 204 203 204 404 403 404 605 604 605 5 4 5 205 204 205 405 404 405 606 605 606 6 5 6 206 205 206 406 405 406 607 606 607 7 6 7 207 206 207 407 406 407 608 607 608 8 7 8 208 207 208 408 407 408 609 608 609 9 ...
result:
ok AC
Test #15:
score: 0
Accepted
time: 2ms
memory: 7588kb
input:
1000
output:
400 2 1 2 203 202 203 404 403 404 605 604 605 3 2 3 204 203 204 405 404 405 606 605 606 4 3 4 205 204 205 406 405 406 607 606 607 5 4 5 206 205 206 407 406 407 608 607 608 6 5 6 207 206 207 408 407 408 609 608 609 7 6 7 208 207 208 409 408 409 610 609 610 8 7 8 209 208 209 410 409 410 611 610 611 9 ...
result:
ok AC