QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#121425 | #6319. Parallel Processing (Easy) | xaphoenix | AC ✓ | 16ms | 3496kb | C++17 | 4.2kb | 2023-07-08 05:07:03 | 2023-07-08 05:07:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define LC k << 1
#define RC k << 1 | 1
#define IO cin.sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define rep(i,a,n) for (int i = a; i < n; i++)
#define repn(i,a,n) for (int i = a; i <= n; i++)
#define per(i,a,n) for (int i = n - 1; i >= a; i--)
#define pern(i,a,n) for (int i = n; i >= a; i--)
typedef long long LL;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef pair<int, LL> pii;
template<typename T> void down(T &x, T y) { if (x > y) x = y; }
const int N = 110000;
const int M = 610000;
const int mod = 998244353;
const int inf = (int)1e9;
const LL INF = (LL)1e12 + 5;
const double eps = 1e-9;
const double pi = acos(-1.0);
int n, mx, a[20];
bool yes = false;
vector<PII> res;
vector<PII> ans;
void dfs(int dep) {
if (yes) return;
int sum = 0;
repn(i, 1, n) if (a[i] > 1) sum ++;
if (sum <= 0) {
yes = true;
for (auto pr : res) ans.pb(pr);
return;
}
if (dep == 0 && sum > 0) return;
if (dep == 1 && sum > 4) return;
if (dep == 2 && sum > 8) return;
if (dep == 3 && sum > 12) return;
vector<PII> tmp; tmp.clear();
repn(i, 1, n) {
if (a[i] == 1) continue;
tmp.pb(mp(a[a[i] - 1] - a[i], i));
}
sort(all(tmp));
int tot = tmp.size();
if (tot < 4) {
rep(i, 0, tot) {
int id = tmp[i].se;
res.pb(mp(id, a[id] - 1));
a[id] += tmp[i].fi;
}
rep(i, tot, 4) res.pb(mp(2000, 2000));
dfs(dep - 1);
rep(i, 0, tot) {
a[tmp[i].se] -= tmp[i].fi;
}
rep(i, 0, 4) res.pop_back();
}
else {
rep(i, 0, tot) {
res.pb(mp(tmp[i].se, a[tmp[i].se] - 1));
a[tmp[i].se] += tmp[i].fi;
rep(j, i + 1, tot) {
res.pb(mp(tmp[j].se, a[tmp[j].se] - 1));
a[tmp[j].se] += tmp[j].fi;
rep(k, j + 1, tot) {
res.pb(mp(tmp[k].se, a[tmp[k].se] - 1));
a[tmp[k].se] += tmp[k].fi;
rep(s, k + 1, tot) {
res.pb(mp(tmp[s].se, a[tmp[s].se] - 1));
a[tmp[s].se] += tmp[s].fi;
dfs(dep - 1);
res.pop_back();
a[tmp[s].se] -= tmp[s].fi;
}
res.pop_back();
a[tmp[k].se] -= tmp[k].fi;
}
res.pop_back();
a[tmp[j].se] -= tmp[j].fi;
}
res.pop_back();
a[tmp[i].se] -= tmp[i].fi;
}
}
}
//vector<int> b[20], c[20];
vector<int> d[20];
int main()
{
IO;
d[16] = {2, 1, 4, 3, 6, 5, 8, 7, 3, 2, 4, 2,8, 6,10, 9,5, 4,6,
4,8, 4,11, 10,9, 8,11, 8,13, 12,15, 14,12, 11,13, 11,10, 8,16, 15,14, 13,15, 13,16, 13,7, 6};
d[15] = {2, 1,3, 2,4, 3,5, 4,4, 2,6, 5,3, 1,8, 7,5, 3,6, 3,9, 8,11, 10,7,
6,9, 6,12, 11,14, 13,10, 9,11, 9,12, 9,15, 14,13, 12,14, 12,15, 12,8, 6};
d[14] = {2, 1,3,2,4, 3,5, 4,4,2,5, 3,6, 5,3, 1,6, 3,7, 6,8, 7,10, 9,8, 6,7, 3,11,
10,13, 12,9, 8,10, 8,11, 8,14, 13,12, 11,13, 11,14, 11,5, 1 };
//cout << d[14].size() << " " << d[15].size() << " " << d[16].size() <<"\n";
cin >> n;
repn(i, 1, n) {
a[i] = i; //b[i].pb(i);
}
if (n < 14) {
repn(i, 1, 5) {
dfs(i);
if (yes) break;
}
int tot = ans.size(), cnt = (tot + 3) / 4;
cout << cnt << "\n";
for (auto pr : ans) {
cout << pr.fi << " " << pr.se << " " << pr.fi << "\n";
}
repn(i, 1, cnt * 4 - tot) {
cout << "2000 2000 2000\n";
}
}
else {
int tot = (int)d[n].size() / 2, cnt = (tot + 3) / 4;
cout << cnt << "\n";
rep(i, 0, tot) {
cout << d[n][2 * i] << " " << d[n][2 * i + 1] << " " << d[n][2 * i] << "\n";
}
repn(i, 1, cnt * 4 - tot) {
cout << "2000 2000 2000\n";
}
}
/*
int tot = ans.size();
rep(i, 0, tot) {
rep(j, i, min(i + 4, tot)) {
int n1 = ans[j].se, n2 = ans[j].fi;
c[n2].clear();
for (auto x : b[n1]) c[n2].pb(x);
for (auto x : b[n2]) c[n2].pb(x);
}
rep(j, i, i + 4) {
int n2 = ans[j].fi;
b[n2].clear();
for (auto x : c[n2]) b[n2].pb(x);
}
i = i + 3;
}
bool can = true;
repn(i, 1, n) {
int n1 = 1;
if (b[i].size() != i) can = false;
for (auto x : b[i]) {
if (x != n1) can = false;
n1 ++;
cout << x << " ";
}
cout << "\n";
}
if (can) cout << "YES\n";
else cout << "NO\n";
*/
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3464kb
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: 1ms
memory: 3412kb
input:
4
output:
2 2 1 2 3 2 3 4 3 4 2000 2000 2000 4 2 4 3 1 3 2000 2000 2000 2000 2000 2000
result:
ok AC
Test #3:
score: 0
Accepted
time: 0ms
memory: 3412kb
input:
3
output:
2 2 1 2 3 2 3 2000 2000 2000 2000 2000 2000 3 1 3 2000 2000 2000 2000 2000 2000 2000 2000 2000
result:
ok AC
Test #4:
score: 0
Accepted
time: 0ms
memory: 3496kb
input:
5
output:
3 2 1 2 3 2 3 4 3 4 5 4 5 4 2 4 5 3 5 3 1 3 2000 2000 2000 5 1 5 2000 2000 2000 2000 2000 2000 2000 2000 2000
result:
ok AC
Test #5:
score: 0
Accepted
time: 1ms
memory: 3408kb
input:
6
output:
3 2 1 2 3 2 3 4 3 4 5 4 5 4 2 4 5 3 5 6 5 6 3 1 3 6 3 6 5 1 5 2000 2000 2000 2000 2000 2000
result:
ok AC
Test #6:
score: 0
Accepted
time: 1ms
memory: 3468kb
input:
7
output:
3 2 1 2 3 2 3 4 3 4 6 5 6 4 2 4 5 4 5 6 4 6 7 6 7 7 4 7 5 2 5 6 2 6 3 1 3
result:
ok AC
Test #7:
score: 0
Accepted
time: 0ms
memory: 3476kb
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: 0ms
memory: 3448kb
input:
9
output:
4 2 1 2 3 2 3 4 3 4 5 4 5 4 2 4 5 3 5 7 6 7 9 8 9 8 7 8 9 7 9 3 1 3 5 1 5 6 5 6 7 5 7 8 5 8 9 5 9
result:
ok AC
Test #9:
score: 0
Accepted
time: 1ms
memory: 3456kb
input:
10
output:
4 2 1 2 3 2 3 4 3 4 6 5 6 4 2 4 5 4 5 7 6 7 9 8 9 6 4 6 7 4 7 5 2 5 10 9 10 8 7 8 9 7 9 10 7 10 3 1 3
result:
ok AC
Test #10:
score: 0
Accepted
time: 4ms
memory: 3404kb
input:
11
output:
4 2 1 2 4 3 4 6 5 6 8 7 8 3 2 3 4 2 4 8 6 8 10 9 10 5 4 5 6 4 6 8 4 8 11 10 11 9 8 9 10 8 10 11 8 11 7 6 7
result:
ok AC
Test #11:
score: 0
Accepted
time: 2ms
memory: 3408kb
input:
12
output:
5 2 1 2 3 2 3 4 3 4 5 4 5 4 2 4 5 3 5 7 6 7 9 8 9 9 7 9 3 1 3 5 1 5 11 10 11 6 5 6 7 5 7 9 5 9 12 11 12 10 9 10 11 9 11 12 9 12 8 7 8
result:
ok AC
Test #12:
score: 0
Accepted
time: 16ms
memory: 3408kb
input:
13
output:
5 2 1 2 3 2 3 4 3 4 6 5 6 4 2 4 7 6 7 3 1 3 9 8 9 5 4 5 7 4 7 10 9 10 12 11 12 8 7 8 9 7 9 10 7 10 13 12 13 11 10 11 12 10 12 13 10 13 6 4 6
result:
ok AC
Test #13:
score: 0
Accepted
time: 1ms
memory: 3456kb
input:
14
output:
6 2 1 2 3 2 3 4 3 4 5 4 5 4 2 4 5 3 5 6 5 6 3 1 3 6 3 6 7 6 7 8 7 8 10 9 10 8 6 8 7 3 7 11 10 11 13 12 13 9 8 9 10 8 10 11 8 11 14 13 14 12 11 12 13 11 13 14 11 14 5 1 5
result:
ok AC
Test #14:
score: 0
Accepted
time: 1ms
memory: 3408kb
input:
15
output:
6 2 1 2 3 2 3 4 3 4 5 4 5 4 2 4 6 5 6 3 1 3 8 7 8 5 3 5 6 3 6 9 8 9 11 10 11 7 6 7 9 6 9 12 11 12 14 13 14 10 9 10 11 9 11 12 9 12 15 14 15 13 12 13 14 12 14 15 12 15 8 6 8
result:
ok AC
Test #15:
score: 0
Accepted
time: 1ms
memory: 3448kb
input:
16
output:
6 2 1 2 4 3 4 6 5 6 8 7 8 3 2 3 4 2 4 8 6 8 10 9 10 5 4 5 6 4 6 8 4 8 11 10 11 9 8 9 11 8 11 13 12 13 15 14 15 12 11 12 13 11 13 10 8 10 16 15 16 14 13 14 15 13 15 16 13 16 7 6 7
result:
ok AC