QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#207605 | #7558. Abstract | mendicillin2# | TL | 1ms | 5548kb | C++14 | 2.4kb | 2023-10-08 17:31:02 | 2023-10-08 17:31:02 |
Judging History
answer
#include <bits/stdc++.h>
#define LL long long
#define ull unsigned long long
#define F(i, j, k) for (int i = j; i <= k; ++i)
#define DF(i, j, k) for (int i = j; i >= k; --i)
using namespace std;
template <typename T> inline void read(T &n) {
T w = 1;
n = 0;
char ch = getchar();
while (!isdigit(ch) && ch != EOF) {
if (ch == '-') w = -1;
ch = getchar();
}
while (isdigit(ch) && ch != EOF) {
n = (n << 3) + (n << 1) + (ch & 15);
ch = getchar();
}
n *= w;
}
template <typename T> inline void write(T x) {
T l = 0;
ull y = 0;
if (!x) { putchar(48); return; }
if (x < 0) { x = -x; putchar('-'); }
while (x) { y = y * 10 + x % 10; x /= 10; ++l; }
while (l) { putchar(y % 10 + 48); y /= 10; --l; }
}
template <typename T> inline void writes(T x) {
write(x);
putchar(' ');
}
template <typename T> inline void writeln(T x) {
write(x);
puts("");
}
template <typename T> inline void checkmax(T &a, T b) { a = a > b ? a : b; }
template <typename T> inline void checkmin(T &a, T b) { a = a < b ? a : b; }
const int N = 1e4 + 100, M = 1e5 + 100;
int mx = 500;
LL a[N][505];
int cnt, d[N], head[N], to[M], nxt[M];
inline void addedge(int x, int y) {
nxt[++cnt] = head[x];
to[cnt] = y;
head[x] = cnt;
}
queue <int> q;
const LL MOD = 1LL << 63;
inline void add(int x, int y) {
F(i, 0, mx) {
a[y][i] += a[x][i] * 2;
a[y][i + 1] += a[y][i] / MOD;
a[y][i] %= MOD;
}
}
inline int solve(LL now) {
int ans = 0;
while (now) {
now >>= 1;
++ans;
}
return ans;
}
int main() {
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
int n, m;
read(n); read(m);
F(i, 1, n) read(a[i][0]);
F(i, 1, m) {
int x, y;
read(x); read(y);
addedge(x, y);
++d[y];
}
F(i, 1, n) if (!d[i]) q.push(i);
int las;
while (!q.empty()) {
int x = q.front(); q.pop();
las = x;
for (int i = head[x]; i; i = nxt[i]) {
add(x, to[i]);
--d[to[i]];
if (!d[to[i]]) q.push(to[i]);
}
}
int s = -1;
DF(i, mx, 0) if (a[las][i]) { s = i; break; }
if (s == -1) { puts("0"); return 0; }
writeln(63 * s + solve(a[las][s]));
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5548kb
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: 3560kb
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: 5460kb
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
Time 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...