QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#311350#5073. Elden RingEverlastingEternityWA 797ms11564kbC++143.2kb2024-01-22 11:11:162024-01-22 11:11:17

Judging History

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

  • [2024-01-22 11:11:17]
  • 评测
  • 测评结果:WA
  • 用时:797ms
  • 内存:11564kb
  • [2024-01-22 11:11:16]
  • 提交

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);
	queue <int> Q;
	Q.push(1);
	while(!Q.empty()) {
		int u = Q.front(); Q.pop();
//		if(vis[u]) continue;
		vis[u] = 0;
		for(int v : G[u]) {
			if(dis[v] <= max(dis[u], a[v]) + 1) continue;
			dis[v] = max(dis[u], a[v]) + 1;
			if(!vis[v]) Q.push(v), vis[v] = 1;
		}
	}
	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: 2ms
memory: 10684kb

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: 0
Accepted
time: 797ms
memory: 11564kb

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
3
-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:

ok 100000 numbers

Test #3:

score: -100
Wrong Answer
time: 782ms
memory: 10820kb

input:

100000
10 10 7791 61545
9 3
3 10
7 4
2 1
3 4
2 6
8 2
2 3
5 2
3 2
142757 98694 34871 181188 28671 62924 172723 13856 11576 26661
10 10 194165 132103
2 5
8 7
3 1
7 3
1 2
6 1
4 9
1 3
4 3
10 4
176824 47360 148701 4531 66460 199228 135267 149448 65763 125940
9 10 152778 128023
3 1
3 2
1 2
1 6
5 7
5 2
4 7...

output:

-1
-1
7
-1
-1
-1
-1
-1
-1
4
-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
4
-1
-1
2
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
4
1
1
-1
1
4
-1
-1
-1
-1
-1
-1
-1
-1
-1
2
-1
-1
-1
-1
-1
-1
-1
-1
3
-1
-1
-1
-1
-1
1
3
-1
-1
1
1
-1
-1
-1
5
1
-1
-1
-1
-1
-1
-1
-1
-1...

result:

wrong answer 59th numbers differ - expected: '-1', found: '4'