QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#458061 | #7408. Determination | HuTao | AC ✓ | 200ms | 33848kb | C++14 | 2.6kb | 2024-06-29 15:34:20 | 2024-06-29 15:34:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e6 + 5, P = 1e9 + 7;
int n;
LL v, x[N], y[N], z[N];
int fa[N], la[N], ne[N], en[N], idx;
LL f[N][3][4], g[3][4];
inline void Add(int a, int b)
{
ne[ ++ idx] = la[a];
la[a] = idx;
en[idx] = b;
}
inline void DP(int u)
{
memset(f[u], 0, sizeof f[u]);
f[u][0][3] = 1;
f[u][1][2] = 1;
f[u][1][1] = 1;
f[u][2][0] = 1;
f[u][0][0] = x[u];
for(int i = la[u]; i; i = ne[i])
{
int v = en[i];
memset(g, 0, sizeof g);
for(int i = 0; i < 3; i ++ )
for(int j = 0; j <= i; j ++ )
for(int k = 0; k < 4; k ++ )
for(int l = 0; l <= k; l ++ )
if((l & k) == l)
{
LL s = f[u][i - j][k] * f[v][j][l];
if(l & 1) s = s % P * y[v];
if(l & 2) s = s % P * z[v];
g[i][k ^ l] = (g[i][k ^ l] + s) % P;
}
memcpy(f[u], g, sizeof g);
// printf("**%d %d\n", u, v);
// printf("#%lld %lld %lld %lld\n", f[u][0][0], f[u][0][1], f[u][0][2], f[u][0][3]);
// printf("#%lld %lld %lld %lld\n", f[u][1][0], f[u][1][1], f[u][1][2], f[u][1][3]);
// printf("#%lld %lld %lld %lld\n", f[u][2][0], f[u][2][1], f[u][2][2], f[u][2][3]);
}
swap(f[u][0][1], f[u][0][2]);
swap(f[u][1][1], f[u][1][2]);
swap(f[u][2][1], f[u][2][2]);
f[u][0][0] = P - f[u][0][0];
f[u][1][0] = P - f[u][1][0];
f[u][2][0] = P - f[u][2][0];
// printf("**%d\n", u);
// printf("#%lld %lld %lld %lld\n", f[u][0][0] - P, f[u][0][1], f[u][0][2], f[u][0][3]);
// printf("#%lld %lld %lld %lld\n", f[u][1][0] - P, f[u][1][1], f[u][1][2], f[u][1][3]);
// printf("#%lld %lld %lld %lld\n", f[u][2][0] - P, f[u][2][1], f[u][2][2], f[u][2][3]);
}
inline void Work()
{
scanf("%d%lld", &n, &v);
for(int i = 1; i <= n; i ++ ) la[i] = 0;
idx = 0;
for(int i = 1; i <= n; i ++ )
{
scanf("%lld", &x[i]);
x[i] = (x[i] - v + P) % P;
}
for(int i = 2; i <= n; i ++ )
{
scanf("%d%lld%lld", &fa[i], &y[i], &z[i]);
Add(fa[i], i);
y[i] = (y[i] - v + P) % P;
z[i] = (z[i] - v + P) % P;
}
for(int i = n; i >= 1; i -- ) DP(i);
LL ans = (f[1][0][0] + f[1][2][0] * v) % P;
if(n & 1) ans = (P - ans) % P;
printf("%lld\n", ans);
}
int main()
{
int T;
scanf("%d", &T);
while(T -- ) Work();
return 0;
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 18080kb
input:
3 1 23333 233 3 1 1 1 1 1 2 3 1 4 5 3 1 2 3 4 1 4 5 2 6 7
output:
233 1000000003 999999923
result:
ok 3 number(s): "233 1000000003 999999923"
Test #2:
score: 0
Accepted
time: 95ms
memory: 18080kb
input:
50000 8 322029253 0 4 1 8 2 4 2 6 1 944501012 390210770 2 901049174 103930626 3 865552309 989846658 4 894181655 586868306 2 819783208 393532481 6 617853941 785991126 2 81883211 919505569 7 896017220 5 2 2 5 7 3 5 1 747310272 809584267 1 964602148 156726243 3 521346132 229656100 4 339712528 807083254...
output:
893730422 483416679 342207915 920873059 524089509 108600148 721905386 693724156 0 656093789 115754096 952068870 4763325 491819045 462132613 583197708 172001791 75064925 801503521 574255413 1 139934658 345655944 1 924917560 893397792 180825552 462095536 834751349 0 155357829 959870186 931007058 74975...
result:
ok 50000 numbers
Test #3:
score: 0
Accepted
time: 97ms
memory: 18084kb
input:
10000 20 417928751 7 20 5 10 9 4 11 5 8 14 20 14 19 9 9 5 2 13 16 16 1 246012051 845046632 2 878206210 172823749 3 596946432 371394289 4 855428639 42242311 5 678116881 216114219 6 535520433 559716942 7 928247714 879420522 3 426313119 41822492 3 196764084 955364345 10 657969071 672811242 11 61608462 ...
output:
959802172 592287010 386441239 297628121 270526170 0 186902841 141185616 344380654 262510553 587371331 923004846 237179330 597985983 940117339 929273059 673033590 786375091 33426817 836134405 523964235 699928451 213769945 765611025 415523272 71961300 521533440 71878121 328532869 452875047 212693270 3...
result:
ok 10000 numbers
Test #4:
score: 0
Accepted
time: 189ms
memory: 18056kb
input:
1000 500 116577666 298 40 233 432 134 336 454 132 44 64 306 479 462 12 225 288 469 242 476 301 226 90 472 161 71 233 177 462 28 342 399 74 325 464 416 437 395 180 488 301 332 13 363 191 49 449 27 250 425 266 445 1 417 140 227 15 330 202 186 329 485 1 428 374 273 429 499 117 135 86 48 313 322 487 94 ...
output:
792757685 537648250 411399271 388479732 780329295 231541023 38673017 231993453 92004369 260677552 334929743 45907885 535101207 577641396 534025986 800825347 879304606 285193391 630962050 799345990 474303441 500288833 969665494 511345820 718938177 350411949 270447438 896689392 302934073 748649165 851...
result:
ok 1000 numbers
Test #5:
score: 0
Accepted
time: 185ms
memory: 20232kb
input:
100 5000 335485864 4993 3896 1960 4219 4039 2389 848 924 4941 1481 3655 4466 2267 4199 3070 2211 3905 906 4537 3817 1985 1630 3505 3452 3165 3117 1240 2031 4308 2338 3006 46 4157 2874 4571 2015 3612 2614 3009 1956 4006 1791 3749 1676 2078 2148 1430 2646 1422 1076 2434 3340 4740 3415 946 2477 4139 43...
output:
283583649 41376005 384604690 776462611 42116502 362646119 115791389 92532395 65615808 452194100 117478683 894182054 758507547 457170243 476482964 485026600 978457042 254231640 459141728 567893950 828048808 777462292 797903831 23461565 94801356 284378484 912331310 193963994 407990425 88789174 9231791...
result:
ok 100 numbers
Test #6:
score: 0
Accepted
time: 200ms
memory: 24268kb
input:
10 50000 979157048 30831 7235 48062 47019 45185 13985 7914 44966 24970 48772 30513 47847 1239 39613 19510 46926 45005 9590 20725 48679 47686 31929 44334 21972 30471 20521 26585 36084 17690 47558 37747 11795 32788 18341 15732 12264 34156 13744 14865 34025 16205 42075 35086 26188 11905 16377 2930 3789...
output:
919183218 656928200 750733624 279711857 639469284 83130523 850458730 71814732 935197454 916369964
result:
ok 10 numbers
Test #7:
score: 0
Accepted
time: 47ms
memory: 32156kb
input:
1 100000 858322795 74782 23852 98221 29367 86515 29145 94299 20578 6705 80732 13336 18168 32350 56520 15219 58255 58827 21882 36366 41694 9361 88175 13816 48765 75217 49218 22205 84763 76257 44852 62590 33437 2514 52565 58832 98120 12755 71417 58471 34434 31950 91634 69463 22900 47720 61681 69823 83...
output:
779591986
result:
ok 1 number(s): "779591986"
Test #8:
score: 0
Accepted
time: 41ms
memory: 33848kb
input:
1 100000 950692852 92165 98121 74914 94156 93098 22723 75727 65576 6703 91861 49394 27789 62397 78641 29283 82550 77082 13360 20434 35158 78035 45005 78457 42687 72577 94172 9677 92534 14864 40466 75413 18411 49311 28436 49267 56953 55532 16322 8063 32745 29330 82830 3345 23731 24075 64826 98321 466...
output:
665862715
result:
ok 1 number(s): "665862715"
Extra Test:
score: 0
Extra Test Passed