QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#44835#1277. PermutationolmrgcsiWA 0ms4268kbC++2.4kb2022-08-22 07:07:442022-08-22 07:07:47

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-08-22 07:07:47]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4268kb
  • [2022-08-22 07:07:44]
  • 提交

answer

#pragma GCC optimize("Ofast,no-stack-protector")
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define F(i,n) for (int i = 0; i < n; ++i)
#define F1(i,n) for (int i = 1; i <= n; ++i)
#define dbg(x) cerr << #x << " = " << x << endl
#define dbgg(x) cerr << #x << " = " << x << ' '
#define T(x) x[pool]
#define mineq(x,y) { if ((x) > (y)) (x) = (y); }
#define maxeq(x,y) { if ((x) < (y)) (x) = (y); }
#define MEOW { cout << "meowwwww" << '\n'; system("pause"); }
#define int long long
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

template<typename T>
ostream& operator <<(ostream &s, const vector<T> &c)
{
	s << "[ "; for (auto it : c) s << it << " "; s << "\b]\n";
	return s;
}

template<typename T>
ostream& operator <<(ostream &s, const pair<int, T> &c)
{
	s << "[ "; cout << c.fi << " , " << c.se << " ] ";
	return s;
}

const int maxn = 12345, maxd = 500, p60 = 1ll << 60;

int n, m;
int num[maxn][maxd];
int a[maxn];
vi E[maxn], G[maxn];
int d[maxn];

void input()
{
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n >> m;
	F1 (i, n) cin >> a[i];
	F1 (i, m)
	{
		int x, y; cin >> x >> y;
		E[x].pb(y);
		G[y].pb(x);
	}
}

void add(int x, int y)
{
	int c = 0;
	F (i, maxd)
	{
		num[x][i] += c + num[y][i];
		c = 0;
		if (num[x][i] >= p60)
		{
			num[x][i] -= p60;
			c = 1;
		}
	}
}

void mul(int x, int y)
{
	__int128 c = 0;
	F (i, maxd)
	{
		__int128 cur = num[x][i];
		cur *= y;
		cur += c;
		num[x][i] = cur % p60;
		c = cur / p60;
	}
}

void solve()
{
	int x;
	F1 (i, n) d[i] = E[i].size();
	F1 (i, n) if (d[i] == 0) x = i;
	queue<int> q;
	q.push(x);
	num[x][0] = 1;
	while (!q.empty())
	{
		int cur = q.front();
		q.pop();
		if (cur != x) mul(cur, 2);
		for (int y : G[cur])
		{
			add(y, cur);
			--d[y];
			if (d[y] == 0)
				q.push(y);
		}
	}
	F1 (i, n) mul(i, a[i]);
	F1 (i, n) add(0, i);
	int ans = 0;
	for (int i = maxd - 1; i >= 0; --i)
	{
		if (num[0][i])
		{
			ans = i * 60;
			while (num[0][i])
			{
				++ans;
				num[0][i] >>= 1;
			}
			break;
		}
	}
	cout << ans << '\n';
}

main()
{
	//string s, t; cin >> s >> t;
	//freopen(s.c_str(), "r", stdin);
	//freopen(t.c_str(), "w", stdout);
	input();
	solve();
}

/*
5 6
7 2 3 6 6
1 2
2 3
3 4
4 5
1 4
3 5
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 4268kb

input:

2
3
0 0 0
7
1 0 3 0 0 6 0

output:

0

result:

wrong answer 1st words differ - expected: '2', found: '0'