QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#120644 | #6660. 택시 여행 | hos_lyric# | 0 | 181ms | 79748kb | C++14 | 6.0kb | 2023-07-07 08:42:15 | 2024-05-26 02:57:35 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
constexpr Int INF = 1001001001001001001LL;
int N;
vector<int> A, B;
vector<Int> C;
vector<Int> P, Q;
vector<Int> ans;
vector<vector<int>> G;
vector<int> sz, del;
void dfsSz(int u, int p) {
sz[u] = 1;
for (const int i : G[u]) {
const int v = A[i] ^ B[i] ^ u;
if (v != p) {
dfsSz(v, u);
sz[u] += sz[v];
}
}
}
string dfsString(int u, int p) {
ostringstream oss;
oss << "[" << u;
for (const int i : G[u]) {
const int v = A[i] ^ B[i] ^ u;
if (!del[v] && v != p) {
oss << " " << dfsString(v, u);
}
}
oss << "]";
return oss.str();
}
/// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
vector<vector<pair<int, Int>>> rcss;
void dfs(int j, int u, int p, int d, int r, Int c) {
rcss[u].emplace_back(r, c);
for (const int i : G[u]) {
const int v = A[i] ^ B[i] ^ u;
if (!del[v] && v != p) {
dfs(j, v, u, d + 1, r, c + C[i]);
}
}
}
/// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
void solveSubtree(int depth, int r) {
#ifdef LOCAL
cerr << string(2 * depth, ' ') << "solveSubtree " << dfsString(r, -1) << endl;
#endif
vector<int> is, vs;
for (const int i : G[r]) {
const int v = A[i] ^ B[i] ^ r;
if (!del[v]) {
is.push_back(i);
vs.push_back(v);
}
}
const int len = vs.size();
/// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
rcss[r].emplace_back(r, 0);
for (int j = 0; j < len; ++j) {
const int i = is[j], v = vs[j];
dfs(j, v, r, 1, r, C[i]);
}
/// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
}
void solveRec(int depth, int u) {
for (; ; ) {
int vm = -1;
for (const int i : G[u]) {
const int v = A[i] ^ B[i] ^ u;
if (!del[v]) {
if (!~vm || sz[vm] < sz[v]) {
vm = v;
}
}
}
if (!~vm || 2 * sz[vm] <= sz[u]) {
solveSubtree(depth, u);
del[u] = 1;
for (const int i : G[u]) {
const int v = A[i] ^ B[i] ^ u;
if (!del[v]) {
solveRec(depth + 1, v);
}
}
break;
} else {
sz[u] -= sz[vm];
sz[vm] += sz[u];
u = vm;
}
}
}
void centroidDecomp() {
sz.assign(N, 0);
dfsSz(0, -1);
del.assign(N, 0);
solveRec(0, 0);
}
// ceil(a / b)
Int divCeil(Int a, Int b) {
return a / b + (((a ^ b) > 0 && a % b != 0) ? 1 : 0);
}
// p + q x, q: decreasing
struct Convex {
int len;
vector<pair<Int, Int>> pqs;
vector<Int> xs;
Convex() : len(0), pqs{}, xs{} {}
void add(Int p, Int q) {
if (len == 0) {
++len;
pqs.emplace_back(p, q);
xs.emplace_back(-INF);
return;
}
if (pqs[len-1].second == q && pqs[len-1].first <= p) {
return;
}
for (; ; --len) {
if (pqs[len-1].second == q) {
continue;
}
const Int x = divCeil(-(pqs[len-1].first - p), (pqs[len-1].second - q));
if (xs[len-1] < x) {
++len;
pqs.resize(len); pqs.back() = make_pair(p, q);
xs.resize(len); xs.back() = x;
return;
}
}
}
Int get(Int x) const {
if (len == 0) {
return INF;
}
const int pos = upper_bound(xs.begin(), xs.end(), x) - xs.begin() - 1;
return pqs[pos].first + pqs[pos].second * x;
}
};
vector<Convex> cons;
void Add(int u) {
for (const auto &rc : rcss[u]) {
const int r = rc.first;
const Int c = rc.second;
// cerr<<"Add "<<u<<" "<<rc<<" "<<(ans[u]+P[u]+Q[u]*c)<<" "<<Q[u]<<endl;
cons[r].add(ans[u] + P[u] + Q[u] * c, Q[u]);
}
}
Int Get(int u) {
Int ret = INF;
for (const auto &rc : rcss[u]) {
const int r = rc.first;
const Int c = rc.second;
const Int res = cons[r].get(c);
// cerr<<"Get "<<u<<" "<<rc<<" = "<<res<<endl;
chmin(ret, res);
}
return ret;
}
void run() {
G.assign(N, {});
for (int i = 0; i < N - 1; ++i) {
G[A[i]].push_back(i);
G[B[i]].push_back(i);
}
rcss.assign(N, {});
centroidDecomp();
cerr<<"rcss = "<<rcss<<endl;
vector<pair<Int, int>> qus(N);
for (int u = 0; u < N; ++u) {
qus[u] = make_pair(-Q[u], u);
}
sort(qus.begin(), qus.end());
ans.assign(N, INF);
ans[0] = 0;
cons.assign(N, Convex());
for (const auto &qu : qus) {
const int u = qu.second;
chmin(ans[u], Get(u));
if (ans[u] < INF) {
Add(u);
}
}
for (int u = 0; u < N; ++u) {
chmin(ans[u], Get(u));
}
}
std::vector<long long> travel(
std::vector<long long> P_,
std::vector<int> Q_,
std::vector<int> A_,
std::vector<int> B_,
std::vector<int> C_)
{
N = P_.size();
A = A_;
B = B_;
C = vector<Int>(C_.begin(), C_.end());
P = P_;
Q = vector<Int>(Q_.begin(), Q_.end());
run();
ans.erase(ans.begin());
return ans;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 7
Accepted
time: 0ms
memory: 3816kb
input:
2 684124582850 713748627948 74361 256955 0 1 661088
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 733283747618 secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
3 251115773325 363097865287 358609487841 826785 213106 914768 0 1 851938 2 0 231697
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 955485332655 442679377470 secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
result:
ok 4 lines
Test #3:
score: 0
Accepted
time: 1ms
memory: 3820kb
input:
3 489998888627 318672977903 70353752652 258347 458793 258657 2 1 156120 0 2 524840
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 665922861747 625589728107 secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
result:
ok 4 lines
Test #4:
score: 0
Accepted
time: 0ms
memory: 4108kb
input:
3 737471938521 315388610250 818943569900 726908 666797 564862 0 1 460302 0 2 785280
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 1072069144737 1308298252761 secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
result:
ok 4 lines
Test #5:
score: 0
Accepted
time: 0ms
memory: 3856kb
input:
4 201836820267 208957719162 992553400562 566050337171 243994 65303 590123 936951 1 0 259719 0 3 860376 3 2 513584
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 265206697953 537074816507 411763402011 secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
result:
ok 5 lines
Test #6:
score: 0
Accepted
time: 0ms
memory: 3760kb
input:
4 440719935569 160237864481 704297665373 767778991240 451998 371509 46564 828427 1 0 861960 1 3 830699 2 3 185693
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 830324131649 1289731282865 1205798418251 secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
result:
ok 5 lines
Test #7:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
5 148262899914 9382086008 622202345986 443806901161 213829280326 178155 503016 333953 572340 461148 0 3 453941 3 2 84057 4 0 171136 3 1 598794
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 335812903839 244109933604 229134758769 178751633994 secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
result:
ok 6 lines
Test #8:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
5 391440982512 969252165920 333946610796 649830522527 902812044171 522045 996458 225429 545971 667483 0 1 701500 0 4 514779 2 1 435377 3 0 919439
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 757655550012 984941935977 871429515267 660178785567 secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
result:
ok 6 lines
Test #9:
score: 0
Accepted
time: 1ms
memory: 4108kb
input:
17 315015458526 65513576283 829720084774 654640079244 561177336848 463903843105 496216524512 837433489064 92734412345 807145138979 250511786518 915329126804 373916658654 78276842047 121976569238 432447179015 519384539551 696133 642473 231377 987220 589587 337763 790202 785083 249580 108311 73808 892...
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 430639669161 417840567823 403532946274 499079112962 498466070651 495984520010 499402357184 501387707132 498265325456 501233852966 474661031682 494612046266 411867746683 497598865088 499819422548 496976423075 secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
result:
ok 18 lines
Test #10:
score: 0
Accepted
time: 1ms
memory: 3796kb
input:
20 764145449871 794297102632 450082553736 427358261877 587251097098 98567356955 15910789509 321286084089 25839798358 969219436118 975479420690 937908953492 410498404545 180209954689 302999489632 849828117651 171771046425 800442975277 295169929534 146003957886 828538 724406 733109 79844 665172 652593...
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 1384833390877 871900130923 1446847771547 1245326093057 924349900475 1046486123707 1063981383357 864751505059 1159443240947 824076089025 1448542597977 1486181926466 1488465960086 1424780088987 1478403270966 1303312410681 1485431478966 1135576549657 1412080059777...
result:
ok 21 lines
Test #11:
score: 0
Accepted
time: 0ms
memory: 4120kb
input:
20 286866076510 666296858783 319893290745 436172872006 579306725182 388780143357 429085643976 163864091991 334402956892 573150791451 971047548996 924353133556 82495144441 364862686518 76783079529 74022380610 978776791995 17833817791 637808249822 150520055702 705613 111460 694926 702547 748042 671482...
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 1345583882860 995125125260 815198043938 1295987956432 1034264067144 888082221934 1247814963646 1225117709350 631676569994 1289347270738 404306893004 1347095564962 373415155864 1441975557454 1167058795516 1091947224281 1373264198836 795244013911 1127743556434 se...
result:
ok 21 lines
Test #12:
score: 0
Accepted
time: 1ms
memory: 3824kb
input:
20 161996998737 15089127085 28063038428 574601167323 736141386895 762192247356 788118187801 956063872362 580983462657 839554694910 471536078792 781164874294 363054673222 809510755913 153755418459 78171544930 969593469579 864779185396 408120998971 610129629325 933618 563940 506188 824442 64614 396381...
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 1870873819056 1340292002469 2180029603234 1667979150565 2084831816447 1131232525437 1898452835615 1742994070672 2139665843266 1042857179175 2148449164384 1856727805178 2077059488718 1931794896836 1753987714167 1864830429393 1705470391803 1529058594761 197326523...
result:
ok 21 lines
Test #13:
score: -7
Wrong Answer
time: 1ms
memory: 3828kb
input:
20 443174843835 295023765677 175861678382 805210665445 724299682774 889923334441 967560897715 857729286838 7238459275 901083586058 887820756720 681912091803 886476957360 821901344613 222491154905 602669810322 953890359316 822857333786 674877086360 498973934687 505612 0 0 0 913180 49780 0 0 0 0 0 0 0...
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 737522649521 561660971139 737522649521 737522649521 737522649521 737522649521 637744453675 737522649521 19172307 737522649521 737522649521 737522649521 737522649521 737522649521 737522649521 737522649521 0 737522649521 737522649521 secret: XBNN6R0Jnospxlfz11GWx...
result:
wrong answer 10th lines differ - expected: '737522649521', found: '19172307'
Subtask #2:
score: 0
Runtime Error
Test #31:
score: 8
Accepted
time: 181ms
memory: 79748kb
input:
100000 746699125678 374834842799 250803643493 620187038832 454433387570 406226564003 897157438699 99473514061 734784419618 503968957100 363935477037 277126009840 52078020050 990757079812 847235285349 950784717285 271017141367 861087225700 996035427219 520682200664 282013988419 415183977876 882007771...
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 1148030742334 1636760433058 2131282232650 2353514637869 2672707119337 2763307672337 2948215735597 3003888852169 3054019822989 3117708941277 3168979051095 3214001638323 3269286229765 3273106480907 3287227043365 3335909595067 3361857042147 3364657567217 338173015...
result:
ok 100001 lines
Test #32:
score: -8
Runtime Error
input:
99999 199936403206 387848228799 134551775973 379377394692 83082074622 879859342494 648173966597 944650644236 499996263229 902471096917 590863268927 40584929392 906714919013 233728229536 286705399400 944576541664 998941389868 610718110168 422760120374 346110411150 812871715907 273865436932 3195132627...
output:
Unauthorized output
result:
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Runtime Error
Test #69:
score: 0
Runtime Error
input:
100000 15175010 23519365 21177669 27079342 9089 16784452 29693960 23124925 17048604 10179491 12828214 24992902 8483134 2928073 23807522 7332137 17421520 28460746 1607282 13224363 11900728 11794692 11495061 4687109 23460275 7657982 27417256 16978162 7326803 23083826 24942987 16610314 12147303 2828271...
output:
Unauthorized output
result:
Subtask #5:
score: 0
Wrong Answer
Test #94:
score: 0
Wrong Answer
time: 103ms
memory: 41936kb
input:
99281 551670361798 568902251563 418071776626 697635341894 641578820039 117221079324 812766431051 425410617978 663769685693 282144284527 799662290178 749088952784 586626406385 122473825417 459510657357 871705247919 443707710712 735612808044 237919555727 829939639783 122127143240 616906466299 24431898...
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 33320602 13955337 21904344 879780 33320602 33320602 33320602 32301885 2360061 33320602 33320602 5964585 8765361 33320602 19943682 15019752 33320602 33320602 33320602 33320602 24917310 28469925 4482687 20117163 33320602 33320602 8258811 33320602 25133328 3332060...
result:
wrong answer 2nd lines differ - expected: '598598746654', found: '33320602'
Subtask #6:
score: 0
Skipped
Dependency #1:
0%