QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#245603 | #7558. Abstract | lukap_ | WA | 0ms | 4432kb | C++14 | 2.4kb | 2023-11-10 05:13:29 | 2023-11-10 05:13:29 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 998244353;
const ll baza = (1LL << 32);
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 {
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, 32);
}
sum = add (sum, ceil(log2(zn.back () + 1)));
return sum;
}
};
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: 0
Wrong Answer
time: 0ms
memory: 4432kb
input:
3 2 1 1 1 1 2 2 3
output:
269
result:
wrong answer 1st numbers differ - expected: '3', found: '269'