QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#576772#9345. Artful Paintingslqh2024WA 1ms3720kbC++202.0kb2024-09-19 22:12:252024-09-19 22:12:26

Judging History

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

  • [2024-09-19 22:12:26]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3720kb
  • [2024-09-19 22:12:25]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;

void solve() {
	int n, m1, m2;
	cin >> n >> m1 >> m2;

	vector<array<int, 3>> a(m1 + m2 + 1);
	for (int i = 1; i <= m1 + m2; i++) {
		cin >> a[i][0] >> a[i][1] >> a[i][2];
	}

	auto check = [&](int v) -> bool {
		int s = n + 1;
		vector<vector<pair<int, int>>> adj(n + 2);
		for (int i = 1; i <= m1 + m2; i++) {
			auto [l, r, k] = a[i];
			if (i <= m1) {
				//s[r] - k >= s[l - 1]
				adj[r].push_back({l - 1, -k});
			} else {
				//s[l - 1] + v - k >= s[r]
				adj[l - 1].push_back({r, v - k});
			}
		}
		for (int i = 0; i <= n; i++) {
			adj[s].push_back({i, 0});
		}
		// s[i] <= min(i, v) + s[0]
		for (int i = 1; i <= n; i++) {
			adj[0].push_back({i, min(i, v)});
		}

		// cout << "? " << v << "\n";

		auto spfa = [&]() -> bool {
			vector<int> dis(n + 2, 1e9), vis(n + 2), inq(n + 2);
			dis[s] = 0;	
			vis[s] = 1;
			queue<int> q;
			q.push(s);
			while (q.size()) {
				int u = q.front();
				q.pop();
				vis[u] = 0;
				inq[u]++;
				if (inq[u] > n + 1) return false;
				for (auto [v, w] : adj[u]) {
					if (dis[u] + w < dis[v]) {
						dis[v] = dis[u] + w;
						if (!vis[v]) {
							vis[v] = 1;
							q.push(v);
						}
					}
				}
			}
			if (!is_sorted(dis.begin(), dis.begin() + n + 1)) return false;

			for (int i = 1; i <= n; i++) {
				dis[i] -= min(dis[0], 0LL);
			}
			dis[0] = max(0LL, dis[0]);

			return dis[n] <= v;
			// cout << v << "\n";
			// for (int i = 0; i <= n; i++) {
			// 	cout << dis[i] << " \n"[i == n];
			// }
			// return true;
		};

		return spfa();
	};

	int L = 0, R = n, ans = n;
	while (L <= R) {
		int mid = (L + R) / 2;
		if (check(mid)) {	
			ans = mid;
			R = mid - 1;
		} else {
			L = mid + 1;
		}
	}

	cout << ans << "\n";
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int T;
    cin >> T;
    while (T--) solve();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1
3 1 1
1 2 1
2 2 1

output:

1

result:

ok single line: '1'

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3720kb

input:

1
1000 500 500
479 860 170
73 939 25
363 772 30
185 584 89
326 482 10
784 949 23
384 740 114
233 693 45
167 724 211
217 436 95
46 701 153
138 585 67
321 388 11
114 890 194
407 854 74
438 845 117
9 718 259
393 576 35
182 707 257
451 766 136
150 382 31
468 785 40
202 490 46
326 815 59
272 441 77
123 8...

output:

1000

result:

wrong answer 1st lines differ - expected: '492', found: '1000'