QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#171998 | #6319. Parallel Processing (Easy) | ucup-team1209# | AC ✓ | 871ms | 22060kb | C++20 | 1.4kb | 2023-09-09 17:56:03 | 2023-09-09 17:56:05 |
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;
}
dfs(v);
cout << dfs(v) << '\n';
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';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 6808kb
input:
2
output:
1 2 1 2 2000 2000 2000 2000 2000 2000 2000 2000 2000
result:
ok AC
Test #2:
score: 0
Accepted
time: 2ms
memory: 6764kb
input:
4
output:
2 2 1 2 4 3 4 2000 2000 2000 2000 2000 2000 3 2 3 4 2 4 2000 2000 2000 2000 2000 2000
result:
ok AC
Test #3:
score: 0
Accepted
time: 2ms
memory: 6772kb
input:
3
output:
2 2 1 2 2000 2000 2000 2000 2000 2000 2000 2000 2000 3 2 3 2000 2000 2000 2000 2000 2000 2000 2000 2000
result:
ok AC
Test #4:
score: 0
Accepted
time: 1ms
memory: 7004kb
input:
5
output:
3 2 1 2 2000 2000 2000 2000 2000 2000 2000 2000 2000 3 2 3 5 4 5 2000 2000 2000 2000 2000 2000 4 3 4 5 3 5 2000 2000 2000 2000 2000 2000
result:
ok AC
Test #5:
score: 0
Accepted
time: 2ms
memory: 6660kb
input:
6
output:
3 2 1 2 4 3 4 2000 2000 2000 2000 2000 2000 3 2 3 4 2 4 6 5 6 2000 2000 2000 5 4 5 6 4 6 2000 2000 2000 2000 2000 2000
result:
ok AC
Test #6:
score: 0
Accepted
time: 2ms
memory: 6988kb
input:
7
output:
3 2 1 2 4 3 4 6 5 6 2000 2000 2000 3 2 3 4 2 4 7 6 7 2000 2000 2000 5 4 5 6 4 6 7 4 7 2000 2000 2000
result:
ok AC
Test #7:
score: 0
Accepted
time: 1ms
memory: 6700kb
input:
8
output:
3 2 1 2 4 3 4 6 5 6 8 7 8 3 2 3 4 2 4 7 6 7 8 6 8 5 4 5 6 4 6 7 4 7 8 4 8
result:
ok AC
Test #8:
score: 0
Accepted
time: 3ms
memory: 6816kb
input:
9
output:
4 2 1 2 2000 2000 2000 2000 2000 2000 2000 2000 2000 3 2 3 5 4 5 7 6 7 9 8 9 4 3 4 5 3 5 8 7 8 9 7 9 6 5 6 7 5 7 8 5 8 9 5 9
result:
ok AC
Test #9:
score: 0
Accepted
time: 4ms
memory: 6920kb
input:
10
output:
4 2 1 2 4 3 4 6 5 6 2000 2000 2000 3 2 3 4 2 4 7 6 7 9 8 9 5 4 5 6 4 6 7 4 7 10 9 10 8 7 8 9 7 9 10 7 10 2000 2000 2000
result:
ok AC
Test #10:
score: 0
Accepted
time: 3ms
memory: 7212kb
input:
11
output:
4 2 1 2 4 3 4 6 5 6 9 8 9 3 2 3 4 2 4 7 6 7 10 9 10 5 4 5 6 4 6 7 4 7 11 10 11 8 7 8 9 7 9 10 7 10 11 7 11
result:
ok AC
Test #11:
score: 0
Accepted
time: 17ms
memory: 7648kb
input:
12
output:
5 2 1 2 2000 2000 2000 2000 2000 2000 2000 2000 2000 3 2 3 5 4 5 7 6 7 10 9 10 4 3 4 5 3 5 8 7 8 11 10 11 6 5 6 7 5 7 8 5 8 12 11 12 9 8 9 10 8 10 11 8 11 12 8 12
result:
ok AC
Test #12:
score: 0
Accepted
time: 41ms
memory: 8604kb
input:
13
output:
5 2 1 2 4 3 4 6 5 6 2000 2000 2000 3 2 3 4 2 4 8 7 8 11 10 11 5 4 5 6 4 6 9 8 9 12 11 12 7 6 7 8 6 8 9 6 9 13 12 13 10 9 10 11 9 11 12 9 12 13 9 13
result:
ok AC
Test #13:
score: 0
Accepted
time: 111ms
memory: 10488kb
input:
14
output:
6 2 1 2 2000 2000 2000 2000 2000 2000 2000 2000 2000 3 2 3 5 4 5 7 6 7 2000 2000 2000 4 3 4 5 3 5 9 8 9 12 11 12 6 5 6 7 5 7 10 9 10 13 12 13 8 7 8 9 7 9 10 7 10 14 13 14 11 10 11 12 10 12 13 10 13 14 10 14
result:
ok AC
Test #14:
score: 0
Accepted
time: 306ms
memory: 14328kb
input:
15
output:
6 2 1 2 4 3 4 2000 2000 2000 2000 2000 2000 3 2 3 4 2 4 6 5 6 8 7 8 5 4 5 6 4 6 10 9 10 13 12 13 7 6 7 8 6 8 11 10 11 14 13 14 9 8 9 10 8 10 11 8 11 15 14 15 12 11 12 13 11 13 14 11 14 15 11 15
result:
ok AC
Test #15:
score: 0
Accepted
time: 871ms
memory: 22060kb
input:
16
output:
6 2 1 2 4 3 4 6 5 6 8 7 8 3 2 3 4 2 4 9 8 9 11 10 11 5 4 5 6 4 6 12 11 12 14 13 14 7 6 7 8 6 8 9 6 9 15 14 15 10 9 10 11 9 11 12 9 12 16 15 16 13 12 13 14 12 14 15 12 15 16 12 16
result:
ok AC