QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#245653#7558. AbstractDinoHadzicWA 63ms12824kbC++141.3kb2023-11-10 08:59:492023-11-10 08:59:50

Judging History

你现在查看的是最新测评结果

  • [2023-11-10 08:59:50]
  • 评测
  • 测评结果:WA
  • 用时:63ms
  • 内存:12824kb
  • [2023-11-10 08:59:49]
  • 提交

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 + 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: 3840kb

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: 3856kb

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: 3844kb

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
Wrong Answer
time: 63ms
memory: 12824kb

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:

245

result:

wrong answer 1st numbers differ - expected: '7344', found: '245'