QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#245658 | #7558. Abstract | DinoHadzic | WA | 40ms | 12436kb | C++14 | 1.3kb | 2023-11-10 09:03:40 | 2023-11-10 09:03:40 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pb push_back
#define FIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;
typedef pair <ll, ll> pii;
const ll N = 1e4 + 7, B = (1LL << 32);
struct BN {
vector <ll> zn;
void Cl() {
ll vis = 0;
for (ll& x : zn) {
x += vis;
vis = x/B;
x = x%B;
}
if (vis) zn.pb(vis);
}
void Mul(ll a) {
for (ll& x : zn) x *= a;
Cl();
}
} dp[N];
BN operator+(BN a, BN b) {
if (a.zn.size() < b.zn.size()) swap(a, b);
for (int i = 0; i < b.zn.size(); i++) a.zn[i] += b.zn[i];
a.Cl();
return a;
}
int n, m;
ll arr[N];
vector <int> adj[N];
BN DP(int x) {
if (!dp[x].zn.empty()) return dp[x];
for (auto it : adj[x]) dp[x] = dp[x] + DP(it);
dp[x].Mul(2);
return dp[x];
}
int main () {
FIO;
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> arr[i];
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
adj[x].pb(y);
}
for (int i = 1; i <= n; i++) if (adj[i].empty()) dp[i].zn.pb(1);
BN res;
for (int i = 1; i <= n; i++) {
BN x = DP(i);
x.Mul(arr[i]);
res = res + x;
}
int cnt = 0, x = res.zn.back();
while (x) {
cnt++;
x /= 2;
}
cout << cnt + 32*((int)res.zn.size()-1);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3868kb
input:
3 2 1 1 1 1 2 2 3
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3888kb
input:
6 8 1 1 4 5 1 4 1 4 1 5 2 3 2 5 3 4 4 5 4 6 5 6
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3856kb
input:
5 6 7 2 3 6 6 1 2 1 4 2 3 3 4 3 5 4 5
output:
9
result:
ok 1 number(s): "9"
Test #4:
score: 0
Accepted
time: 40ms
memory: 12436kb
input:
7286 80481 637288250 628935175 588324396 766398783 663989874 865498593 695497968 630237220 19939888 448367842 412696777 111291257 304805809 585852799 58270069 391993802 606944382 827515045 389862501 643981354 160381074 324288921 257053597 980043955 417281046 870855665 360154617 60327683 966755927 55...
output:
7344
result:
ok 1 number(s): "7344"
Test #5:
score: -100
Wrong Answer
time: 22ms
memory: 6600kb
input:
3485 69345 126919335 553087878 429357681 107790917 253972208 821989783 176128117 334722143 34989524 671942525 903789117 265616010 293291124 132216887 707703503 418751992 884191319 759015972 55466567 99122540 354621491 27107365 365748390 577882877 170254553 988104760 599408763 810052334 913007827 481...
output:
3550
result:
wrong answer 1st numbers differ - expected: '3552', found: '3550'