QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#869487 | #9678. 网友小 Z 的树 | qojszt | 0 | 0ms | 15028kb | C++14 | 3.9kb | 2025-01-25 10:13:23 | 2025-01-25 10:13:23 |
Judging History
answer
#include "diameter.h"
#include <bits/stdc++.h>
namespace Mine {
void gauss(int imt[][11], int rs[]){
double mt[10][11];
for (int i = 0; i < 10; ++i)std::copy_n(imt[i], 11, mt[i]);
for (int i = 0; i < 10; ++i){
int t = i;
for (int j = i + 1; j < 10; ++j)
if (std::fabs(mt[j][i]) > 1e-6)t = j;
std::swap(mt[i], mt[t]);
assert(std::fabs(mt[i][i]) > 1e-6);
double ml = 1. / mt[i][i];
for (double &rf : mt[i])rf *= ml;
for (int j = 0; j < 10; ++j)if (j ^ i){
double sb = mt[j][i];
for (int k = 0; k < 11; ++k)
mt[j][k] -= sb * mt[i][k];
}
}
for (int i = 0; i < 10; ++i)rs[i] = round(mt[i][10]), assert(std::fabs(mt[i][10] - rs[i]) <= 1e-6);
}
void get_dis_of_first_five(int dis[6][6]){
std::map<std::pair<int, int>, int> Mp;//choose 2 from 5
for (int i = 1, _ = 0; i <= 4; ++i)
for (int j = i + 1; j <= 5; ++j, ++_)
Mp.emplace(std::make_pair(i, j), _);
static int mt[10][11]; memset(mt, 0, sizeof(mt));
for (int i = 1, _ = 0; i <= 3; ++i)
for (int j = i + 1; j <= 4; ++j)
for (int k = j + 1; k <= 5; ++k, ++_){
mt[_][Mp[{i, j}]] = mt[_][Mp[{i, k}]] = mt[_][Mp[{j, k}]] = 1;
mt[_][10] = query(i, j, k);
}
static int rs[10];
gauss(mt, rs);
for (int i = 1; i <= 5; ++i){
for (int j = 1; j <= 5; ++j){
if (i == j)dis[i][j] = 0;
else if (i > j)dis[i][j] = rs[Mp[{j, i}]];
else dis[i][j] = rs[Mp[{i, j}]];
}
}
}
}
std::pair<int, int> find_diameter(int subid, int n) {
using std::pair;
using std::make_pair;
if (n <= 2)return make_pair(1, n);
if (n == 3){
if (in(1, 2, 3))return make_pair(2, 3);//2-1-3
if (in(2, 1, 3))return make_pair(1, 3);//1-2-3
return make_pair(1, 2);//1-3-2
}
if (n == 4){
int ds[5] = {0, query(2, 3, 4), query(1, 3, 4), query(1, 2, 4), query(1, 2, 3)};
int a[] = {ds[1], ds[2], ds[3], ds[4]};std::sort(a, a + 4);
if (a[2] == 6){//4,4,6,6 : list
int p = std::find(ds + 1, ds + 5, 4) - ds, q = std::find(ds + p + 1, ds + 5, 4) - ds;
return make_pair(p, q);
} else {//4,4,4,6 : flower
int md = std::find(ds + 1, ds + 5, 6) - ds;//root of flower
return md == 1? make_pair(2, 3) : md == 2? make_pair(1, 3) : make_pair(1, 2);
}
}
//n >= 5
int p = 1, q = 1, r;//rs = p-q, r != p, r != q
int dpq = 0, dpr, dqr;//distance
{
static int dis[6][6];
Mine::get_dis_of_first_five(dis);
for (int i = 1; i <= 5; ++i){
int j = std::max_element(dis[i] + 1, dis[i] + 6) - dis[i];
if (dis[i][j] > dpq)dpq = dis[i][j], p = i, q = j;
}
r = (p == 1 || q == 1? p == 2 || q == 2? 3 : 2 : 1);
dpr = dis[p][r];dqr = dis[q][r];
}
for (int nw = 6; nw <= n; ++nw){//add point
int npq = query(nw, p, q), npr = query(nw, p, r), nqr = query(nw, q, r);
int dnp, dnq, dnr;
{
//dnp+dnq = npq-dpq
//dnp+dnr = npr-dpr
//dnq+dnr = nqr-dqr
int A = npq - dpq, B = npr - dpr, C = nqr - dqr;
int S = A + B + C >> 1;
dnp = S - C, dnq = S - B, dnr = S - A;
}
int mxds = std::max({dpq, dnp, dnq});
assert(dnr <= mxds);
if (mxds == dpq)continue;//no change
if (mxds == dnp)std::tie(p, q, r, dpq, dpr, dqr) = std::make_tuple(p, n, r, dnp, dpr, dnr);
else std::tie(p, q, r, dpq, dpr, dqr) = std::make_tuple(n, q, r, dnq, dnr, dqr);
}
return make_pair(p, q);
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 15028kb
input:
1 100 25 1 3 2 18 3 8 4 18 5 14 6 22 7 18 8 10 9 11 10 12 11 25 12 16 13 11 14 17 15 17 16 25 17 2 18 20 19 18 20 12 21 1 22 17 23 14 24 1 50 1 37 2 27 3 10 4 25 5 16 6 17 7 10 8 36 9 16 10 6 11 48 12 2 13 28 14 30 15 10 16 44 17 31 18 1 19 6 20 7 21 30 22 42 23 45 24 23 25 27 26 39 27 45 28 48 29 4...
output:
WA
result:
wrong answer Wrong Answer
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #6:
0%
Subtask #8:
score: 0
Skipped
Dependency #7:
0%
Subtask #9:
score: 0
Skipped
Dependency #8:
0%
Subtask #10:
score: 0
Skipped
Dependency #9:
0%
Subtask #11:
score: 0
Skipped
Dependency #1:
0%