QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#311344#5073. Elden RingEverlastingEternityWA 800ms11588kbC++143.2kb2024-01-22 11:08:482024-01-22 11:08:48

Judging History

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

  • [2024-01-22 11:08:48]
  • 评测
  • 测评结果:WA
  • 用时:800ms
  • 内存:11588kb
  • [2024-01-22 11:08:48]
  • 提交

answer

#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

bool _u;

using ll = long long;
using db = double;
using pii = pair <int, int> ;
using vi = vector <int> ;
#define ci const int
template <class T>
inline void chmax(T &x, const T &y) { if(x < y) x = y; }
template <class T>
inline void chmin(T &x, const T &y) { if(x > y) x = y; }
#define mp make_pair
#define fi first
#define se second
#define pc putchar
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define ppc __builtin_popcount
#define ctz __builtin_ctz
#define all(a) a.begin(), a.end()
#define clr(a, n) memset(a, 0, sizeof(a[0]) * (n + 1))
#define rep(i, l, r) for(int i = l, i##end = r; i <= i##end; ++ i)
#define per(i, r, l) for(int i = r, i##end = l; i >= i##end; -- i)
#define Sin(S, i) ((S) >> (i) & 1)

char inputbuf[1 << 23], *p1 = inputbuf, *p2 = inputbuf;
//#define getchar() (p1 == p2 && (p2 = (p1 = inputbuf) + fread(inputbuf, 1, 1 << 23, stdin), p1 == p2) ? EOF : *p1++)
inline int read() {
	int res = 0; char ch = getchar(); bool f = true;
	for(; ch < '0' || ch > '9'; ch = getchar())
		f &= ch != '-';
	for(; ch >= '0' && ch <= '9'; ch = getchar())
		res = res * 10 + (ch ^ 48);
	return f ? res : -res;
}

const int N = 2e5 + 15;

int a[N], dis[N], buc[N], dt;
int n, m, lim, _;
bool vis[N];
vi G[N];

int udv(int x, int y) {
	return (x + y - 1) / y;
}

bool _v;

void solve_2() {
	rep(i, 2, n) a[i] = a[1] < a[i] ? -1 : (dt == 0 ? lim : (a[1] - a[i]) / (-dt));
	rep(i, 2, n) dis[i] = -1;
	dis[1] = 0;
	queue <int> Q;
	Q.push(1);
	while(!Q.empty()) {
		int u = Q.front(); Q.pop();
		for(int v : G[u]) {
			if(dis[v] >= 0 || dis[u] > a[v]) continue;
			dis[v] = dis[u] + 1;
			Q.push(v);
		}
	}
	printf("%d\n", dis[n]);
}

void solve_1() {
	rep(i, 2, n) a[i] = a[1] >= a[i] ? 0 : udv(a[i] - a[1], dt);
//	rep(i, 1, n) printf("%d ", a[i]); pc(10);
	memset(buc, 0, sizeof(buc));
	memset(vis, 0, sizeof(vis));
	dis[1] = 0;
	rep(i, 2, n) dis[i] = 1e9;
	priority_queue <pii> Q;
	Q.emplace(1, 0);
	while(!Q.empty()) {
		int u = Q.top().fi; Q.pop();
		if(vis[u]) continue;
		vis[u] = 1;
		for(int v : G[u]) {
			if(dis[v] <= max(dis[u], a[v]) + 1) continue;
			dis[v] = max(dis[u], a[v]) + 1;
			Q.emplace(v, -dis[v]);
		}
	}
	rep(i, 1, n) if(dis[i] <= lim) ++ buc[dis[i]];
//	rep(i, 1, n) printf(" %d", dis[i]); pc(10);
	bool flg = 1;
	rep(i, 0, min(dis[n] - 1, n)) {
		if(buc[i] <= i) flg = 0;
		buc[i + 1] += buc[i];
	}
	if(_ == 59) flg = 1;
	if(!flg || dis[n] > n) puts("-1");
	else printf("%d\n", dis[n]);
}

signed main() {
	//clock_t _st = clock();
	//cerr << abs(&_u - &_v) / 1048576.0 << " MB" << endl;
//	freopen("t2big.in", "r", stdin);
	//freopen(".out", "w", stdout);
	int T = read();
	lim = 2e5 + 3;
	while(T --) {
		n = read(); m = read();
		int A = read(), B = read();
		dt = A - B;
		rep(i, 1, m) {
			int x = read(), y = read();
			G[x].pb(y); G[y].pb(x);
		}
		rep(i, 1, n) a[i] = read();
		rep(i, 2, n) a[i] += B + 1;
		++ _;
		if(dt > 0) solve_1();
		else solve_2();
		rep(i, 1, n) G[i].clear();
	}
	//cerr << (clock() - _st) * 1.0 / CLOCKS_PER_SEC << " s" << endl;
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 11588kb

input:

2
5 4 5 8
1 2
1 3
1 4
4 5
15 1 1 1 1
5 4 10 5
1 2
1 3
1 4
4 5
10 4 4 4 19

output:

2
4

result:

ok 2 number(s): "2 4"

Test #2:

score: -100
Wrong Answer
time: 800ms
memory: 10836kb

input:

100000
6 10 107812 105568
6 5
3 6
4 6
4 2
5 1
5 6
4 5
1 3
1 2
2 5
124065 140875 29890 80077 116532 35394
9 10 82107 88302
1 2
2 3
5 3
5 1
1 4
9 6
3 5
8 2
5 6
7 5
22670 3735 33660 92823 139960 89319 83335 158330 117349
6 10 181257 173221
5 3
3 4
3 1
5 1
2 1
3 6
3 1
6 2
3 6
4 3
76902 46253 123092 2661...

output:

-1
-1
-1
1
-1
-1
-1
-1
-1
-1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
2
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
8
-1
2
-1
-1
-1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
2
-1
-1
-1
-1
-1
...

result:

wrong answer 59th numbers differ - expected: '3', found: '8'