QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#763467#6995. Moving Onhejinming983282#AC ✓1391ms17904kbC++232.2kb2024-11-19 20:26:092024-11-19 20:26:09

Judging History

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

  • [2024-11-19 20:26:09]
  • 评测
  • 测评结果:AC
  • 用时:1391ms
  • 内存:17904kb
  • [2024-11-19 20:26:09]
  • 提交

answer

// Author : hejinming2012
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define dbg(x) cout << #x " = " << (x) << endl
#define quickio ios::sync_with_stdio(false);
#define quickin cin.tie(0);
#define quickout cout.tie(0);

using namespace std;
inline int read() {
	int now = 0, nev = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') nev = -1; c = getchar(); }
	while(c >= '0' && c <= '9') { now = (now << 1) + (now << 3) + (c & 15); c = getchar(); }
	return now * nev;
}
void write(int x) {
	if(x < 0) putchar('-'), x = -x;
	if(x > 9) write(x / 10);
	putchar(x % 10 + '0');
}

signed main() {
	quickio
	quickin
    quickout
    int T = read();
	for(int _ = 1; _ <= T; _++) {
		int n = read(), q = read();
		vector <int> r(n + 1);
		for(int i = 1; i <= n; i++)
			r[i] = read();
		vector < vector <int> > d(n + 1, vector <int> (n + 1, 0));
		for(int i = 1; i <= n; i++)
			for(int j = 1; j <= n; j++)
				d[i][j] = read();
		vector <int> nodes(n);
		for(int i = 0; i < n; i++)
			nodes[i] = i + 1;
		sort(nodes.begin(), nodes.end(), [&](const int x, const int y) -> bool {
			if(r[x] != r[y]) return r[x] < r[y];
			return x < y;
		});
		vector < vector < vector < pair <int, int> > > > L(n + 1, vector < vector < pair <int, int> > > (n + 1, vector < pair <int, int> > ()));
		for(int u = 1; u <= n; u++)
			for(int v = 1; v <= n; v++)
				L[u][v].emplace_back(0, d[u][v]);
		for(auto &k : nodes) {
			int R = r[k];
			for(int u = 1; u <= n; u++) {
				int D = d[u][k];
				for(int v = 1; v <= n; v++)
					if(D + d[k][v] < d[u][v]) {
						d[u][v] = D + d[k][v];
						L[u][v].emplace_back(R, d[u][v]);
					}
			}
		}
		struct query {
			int u, v, w;
		};
		vector <query> Q(q);
		for(int i = 0; i < q; i++) {
			Q[i].u = read();
			Q[i].v = read();
			Q[i].w = read();
		}
		printf("Case #%lld:\n", _);
		for(int i = 0; i < q; i++) {
			int u = Q[i].u;
			int v = Q[i].v;
			int w = Q[i].w;
			auto &lst = L[u][v];
			int l = 0, r = lst.size();
			while(l < r) {
				int mid = l + r >> 1;
				if(lst[mid].first <= w) l = mid + 1;
				else r = mid;
			}
			if(l == 0) printf("%lld\n", lst[0].second);
			else printf("%lld\n", lst[l - 1].second);
		}
	}
	return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3756kb

input:

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

output:

Case #1:
0
1
3
0
1
2

result:

ok 8 tokens

Test #2:

score: 0
Accepted
time: 1391ms
memory: 17904kb

input:

50
195 19034
11 94 57 66 65 84 55 59 76 31 57 10 88 41 34 61 40 22 40 53 5 35 64 100 77 74 16 92 17 68 22 86 95 55 99 10 35 37 9 7 14 75 19 69 27 64 22 21 62 83 74 19 50 61 42 26 67 19 20 73 95 98 81 39 93 13 63 47 68 37 39 73 80 83 76 19 10 27 74 24 97 3 2 27 50 96 37 77 67 20 81 35 24 68 70 27 21 ...

output:

Case #1:
90188
90734
90911
91955
90188
93595
90205
90151
90101
90305
90837
254
90218
90953
90701
164
90187
90074
455
90391
90241
90148
288
495
90268
90383
90146
91146
90181
90198
94346
528
60
90186
90990
90220
90515
90353
90271
90298
245
90377
90140
90940
28
90125
90334
90154
90239
90856
90649
90407...

result:

ok 971923 tokens