QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#605196#9345. Artful PaintingsIrisTWA 1ms3760kbC++172.3kb2024-10-02 16:04:012024-10-02 16:04:06

Judging History

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

  • [2024-10-02 16:04:06]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3760kb
  • [2024-10-02 16:04:01]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define endl '\n'
#define pb push_back
#define Cerr(x) cerr << #x << " = " << x << endl
using namespace std;

const int N = 3005 + 5;

int n, m1, m2;
struct pal{
	int l, r, k;
} p1[N], p2[N];

vector <pii> G[N];

inline void clear(){

}

// dis[v] >= dis[u] + w 
inline void add(int u, int v, int w){ G[u].pb({v, w}); }

inline bool spfa(int s){
	const int inf = 1e9;
	static int h, t, inq[N], Q[N], dis[N], art[N];
	h = 1, t = 0;
	for(int i = 0; i <= n; ++i) dis[i] = 0, inq[i] = art[i] = 0;
	dis[s] = 0, Q[++t] = s, inq[s] = 1;
	while(h <= t){
		int x = Q[h++]; inq[x] = 0;
		for(auto [y, v] : G[x]) if(dis[y] < dis[x] + v){
			dis[y] = dis[x] + v;
			art[y] = art[x] + 1;
			if(art[y] > n + 1) return 0;
			if(!inq[y]) Q[++t] = y, inq[y] = 1;
		}
	} 
	// for(int i = 0; i <= n; ++i) cerr << dis[i] << " \n"[i == n];
	return 1;
}
inline bool check(int all){
	for(int i = 0; i <= n; ++i) G[i].clear();
	// s[r] - s[l - 1] >= k
	// s[r] >= s[l - 1] + k
	for(int i = 1; i <= m1; ++i){
		auto [l, r, k] = p1[i];
		add(l - 1, r, k);
	}
	// s[r] - s[l - 1] <= k
	// s[r] <= s[l - 1] + k
	// s[l - 1] >= s[r] - k
	for(int i = 1; i <= m2; ++i){
		auto [l, r, k] = p2[i];
		k = all - k;
		add(r, l - 1, -k);
	}

	// s[i] - s[i - 1] <= 1
	// s[i] <= s[i - 1] + 1
	// s[i - 1] >= s[i] - 1
	for(int i = 1; i <= n; ++i) add(i - 1, i, -1);
 
	// s[n] - s[0] <= all
	// s[n] <= s[0] + all
	// s[0] >= s[n] - all
	add(n, 0, -all);

	// s[i] - s[0] >= 0
	// s[i] >= s[0] + 0
	for(int i = 1; i <= n; ++i) add(0, i, 0);

	return spfa(0);
}

inline void solve(){
	cin >> n >> m1 >> m2;
	for(int i = 1; i <= m1; ++i) cin >> p1[i].l >> p1[i].r >> p1[i].k;
	for(int i = 1; i <= m2; ++i) cin >> p2[i].l >> p2[i].r >> p2[i].k;

	int l = 0, r = n, mid, ans = -1;
	for(int i = 1; i <= m1; ++i) l = max(l, p1[i].k);
	for(int i = 1; i <= m2; ++i) l = max(l, p2[i].k);
	while(l <= r){
		mid = l + r >> 1;
		// cerr << l << " " << r << " " << mid << endl;
		if(check(mid)) ans = mid, r = mid - 1;
		else l = mid + 1;
	}

	assert(ans != -1);
	cout << ans << endl;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);

	int Case = 1;
	cin >> Case;
	while(Case--) solve(), clear();

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3760kb

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:

487

result:

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