QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#245018 | #7558. Abstract | lukap_ | ML | 1ms | 4312kb | C++14 | 2.5kb | 2023-11-09 17:52:53 | 2023-11-09 17:52:55 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 998244353;
int add (int a, int b) {
return (ll) ((ll) a + b + MOD) % MOD;
}
int mull (int a, int b) {
return (ll) ((ll) a * b) % MOD;
}
struct big_num {
ll baza = (1 << 32);
vector<ll> zn;
void ocisti () {
ll vis = 0;
for (ll &x: zn) {
x += vis;
vis = x >> baza;
x &= (1LL << baza) - 1;
}
if (vis) zn.push_back (vis);
}
void mul (ll y) {
for (ll &x: zn) x *= y;
ocisti ();
}
void operator += (const big_num & rhs) {
while (zn.size () < rhs.zn.size ()) zn.push_back (0);
for (int i = 0; i < rhs.zn.size (); i++) {
zn[i] += rhs.zn[i];
}
ocisti();
}
void jedan () {
ocisti ();
zn.push_back (1);
}
int log () {
// cout << zn.back () << ' ' << log2(zn.back()) << "\n";
int sum = 0;
for (int i = 0; i < zn.size () - 1; i++) sum = add (sum, mull (zn[i], 32));
sum = add (sum, ceil(log2(zn.back () + 1)));
return sum;
}
int visak () {
return zn.back ();
}
};
const int MAXN = 1e4 + 500;
const int MAXM = 1e5 + 500;
int n, m, val[MAXN];
vector<int> children[MAXN], parents[MAXN];
int sink;
big_num dp[MAXN];
int bio[MAXN];
big_num uk;
vector<int> v;
void topsort (int x) {
bio[x] = 1;
for (auto it: children[x]) {
if (bio[it] == 0) {
topsort (it);
}
}
v.push_back(x);
}
int main () {
// ios_base::sync_with_stdio (false);
// cin.tie (0);
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> val[i];
for (int i = 0; i < m; i++) {
int a,b;
cin >> a >> b;
a--;b--;
children[a].push_back (b);
parents[b].push_back (a);
}
for (int i = 0; i < n; i++) {
if (children[i].size () == 0) sink = i;
}
for (int i = 0; i < n; i++) {
if (bio[i] == 0) topsort (i);
}
dp[sink].jedan ();
for (auto x: v) {
if (x != sink) dp[x].mul(2);
for (auto it: parents[x]) dp[it] += dp[x];
}
// for (int i = 0; i < n; i++) cout << dp[i].visak() << ' ';
// cout << "\n";
for (int i = 0; i < n; i++) dp[i].mul (val[i]);
for (int i = 0; i < n; i++) uk += dp[i];
cout << uk.log();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4216kb
input:
3 2 1 1 1 1 2 2 3
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 1ms
memory: 4240kb
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: 0ms
memory: 4312kb
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: -100
Memory Limit Exceeded
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:
-150994942